def publish_results()

in functions/source/keyword-extraction/lambda_function.py [0:0]


def publish_results(decoded_data,data):
    '''
    Publish results to dynamodb and websocket
    ''' 
    try:
        transcripts_table = dynamodb.Table(transcripts_table_name)
        connections_table = dynamodb.Table(connections_table_name)
        start_time = decoded_data["StartTime"][0]
        end_time = decoded_data["EndTime"][0]
        speaker = decoded_data["Speaker"][0]
        comment = decoded_data["Transcript"][0]
        is_keyword = decoded_data["KeywordPresence"][0]
        keywords = decoded_data["Keywords"]
        transaction_id = data["TransactionId"]
        time_ = datetime.datetime.now().strftime('%H:%M:%S') 
        transcripts_table.put_item(
            Item = {
                'TransactionId': transaction_id,
                'StartTime': start_time,
                'EndTime': end_time,
                'Speaker': speaker,
                'Transcript': comment,
                'KeywordPresence': is_keyword,
                'Keywords': keywords,
                'LoggedOn': time_
            }
        )
        connection_id=getConnectionId(transaction_id,connections_table)
        wsclient = boto3.client('apigatewaymanagementapi',endpoint_url = os.environ['WEBSOCKET_URL'])
        response = wsclient.post_to_connection(
            Data=json.dumps({"TransactionId": transaction_id, "StartTime": str(start_time), "EndTime": str(end_time), "Speaker": speaker,"Transcript": comment, "KeywordPresence": is_keyword, "Keywords": keywords}),
            ConnectionId=connection_id)
        
    except Exception as e:
        print('Exception while sending to websocket & dynamodb',str(e))