Skip to content

Instantly share code, notes, and snippets.

@sherlockholmes
Last active March 14, 2019 14:02
Show Gist options
  • Select an option

  • Save sherlockholmes/a1377e9e5b1220d86fe4f82aad94486d to your computer and use it in GitHub Desktop.

Select an option

Save sherlockholmes/a1377e9e5b1220d86fe4f82aad94486d to your computer and use it in GitHub Desktop.
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