daily pastebin goal
81%
SHARE
TWEET

Untitled

a guest Mar 18th, 2019 52 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. from __future__ import print_function # Python 2/3 compatibility
  2. import os, boto3, json
  3.  
  4. client = boto3.client('comprehend')
  5.  
  6. def lambda_handler(event, context):
  7.     sentiment=client.detect_sentiment(Text=event['inputTranscript'],LanguageCode='en')['Sentiment']
  8.     sentimentscore=client.detect_sentiment(Text=event['inputTranscript'],LanguageCode='en')['SentimentScore']
  9.     comment=event['inputTranscript']
  10.     customeremail=event['customeremail']
  11.     customername=event['customername']
  12.     if sentiment=='NEGATIVE':
  13.         result = {
  14.                 "statusCode": 200,
  15.                 "headers": {
  16.                     "Content-Type": "application/json"
  17.                 },
  18.                 "sessionAttributes": {
  19.                     "sentiment": sentiment,
  20.                     "sentimentscore": sentimentscore
  21.                     }
  22.                 }
  23.     else:
  24.         result ={
  25.             "statusCode": 200,
  26.             "headers": {
  27.                 "Content-Type": "application/json"
  28.             },
  29.             "sessionAttributes": {
  30.                 "sentiment": sentiment,
  31.                 "sentimentscore": sentimentscore
  32.             }
  33.         }
  34.     dynamodb = boto3.resource('dynamodb', region_name='us-east-1')
  35.     table = dynamodb.Table('testtable')
  36.     table.put_item(
  37.         Item={
  38.                'email': customeremail,
  39.                'customername': customername,
  40.                'confidencescore': sentiment,
  41.                'comment':comment ,
  42.             }
  43.         )
  44.  
  45.     return result
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top