Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement