Last active
March 14, 2019 14:02
-
-
Save sherlockholmes/a1377e9e5b1220d86fe4f82aad94486d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from __future__ import print_function # Python 2/3 compatibility | |
| import os, boto3, json | |
| client = boto3.client('comprehend') | |
| def lambda_handler(event, context): | |
| sentiment=client.detect_sentiment(Text=event['inputTranscript'],LanguageCode='en')['Sentiment'] | |
| sentimentscore=client.detect_sentiment(Text=event['inputTranscript'],LanguageCode='en')['SentimentScore'] | |
| comment=event['inputTranscript'] | |
| customeremail=event['customeremail'] | |
| customername=event['customername'] | |
| if sentiment=='NEGATIVE': | |
| result = { | |
| "statusCode": 200, | |
| "headers": { | |
| "Content-Type": "application/json" | |
| }, | |
| "sessionAttributes": { | |
| "sentiment": sentiment, | |
| "sentimentscore": sentimentscore | |
| } | |
| } | |
| else: | |
| result ={ | |
| "statusCode": 200, | |
| "headers": { | |
| "Content-Type": "application/json" | |
| }, | |
| "sessionAttributes": { | |
| "sentiment": sentiment, | |
| "sentimentscore": sentimentscore | |
| } | |
| } | |
| dynamodb = boto3.resource('dynamodb', region_name='us-east-1') | |
| table = dynamodb.Table('testtable') | |
| table.put_item( | |
| Item={ | |
| 'email': customeremail, | |
| 'customername': customername, | |
| 'confidencescore': sentiment, | |
| 'comment':comment , | |
| } | |
| ) | |
| return result | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment