【发布时间】:2020-11-29 16:11:33
【问题描述】:
我创建了一个 amazon lex 聊天机器人,可以为组织提高票证。它要求 5 个输入字段(empid、name、description、impact、urgency、emailid)并存储在 aws lambda 中。到目前为止,我一直在通过 python 中的 aws lambda 将从聊天机器人获得的输入字段存储到 dynamodb 中。现在,我想检查特定用户提出票证的次数。我是数据库概念的初学者。
对话示例。
User:Hi
Chatbot:Enter your id?
User:q123
Chatbot:enter your name?
User:xxx
Chatbot:enter your desc?
User:sdbsb
Chatbot:enter your emailid?
User:xxx@yyy.com
Chatbit:your ticket is raised.
User:I want to check till now the number of tickets I have raised
Chatbot:you have raised 4 tickets till now.
示例代码:
import json
import logging
import re
import http.client
import mimetypes
import boto3
logger = logging.getLogger()
logger.setLevel(logging.DEBUG)
def close():
val= {
"dialogAction":
{
"fulfillmentState":"Fulfilled",
"type":"Close",
"message":
{
"contentType":"PlainText",
"content":"Hey your ticket has been raiised"
},
'responseCard': {
'version': '1',
'contentType': 'application/vnd.amazonaws.card.generic',
}
}
print(val)
return val
def lambda_handler(event, context):
dynamodb=boto3.resource('dynamodb')
table=dynamodb.Table('employee')
slots = event['currentIntent']['slots']
empidemployee= event['currentIntent']["slots"]["empidemployee"]
latestdesc= event['currentIntent']["slots"]["latestdesc"]
latestservice= event['currentIntent']["slots"]["latestservice"]
latestimpactvalue= event['currentIntent']["slots"]["latestimpactvalue"]
latesturgency= event['currentIntent']["slots"]["latesturgency"]
basicinfo=event['currentIntent']["slots"]["basicinfo"]
jsonStrings ={
'empidemployee':empidemployee,
'desc':latestdesc,
'service':latestservice,
'impact':latestimpactvalue,
'urgency':latesturgency,
'emailid':basicinfo
}
print(jsonStrings)
table.put_item(
Item=jsonStrings
)
val=close()
return val
return {
'statusCode':200,
'body':'added'
}
【问题讨论】:
-
你的表定义是什么样的?您是如何定义主键的?
标签: python aws-lambda amazon-dynamodb aws-lex