微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

在AWS Lex QnA中使用Lambda挂钩

如何解决在AWS Lex QnA中使用Lambda挂钩

我正在用Lex构建QnA Bot,在其中,对于某些问题,将使用lambda挂钩,然后根据所发布的问题吐出一个答案。 按照lambda挂钩指示,“ lambda处理程序必须返回修改后的事件对象。”从event.res(需要进行操作)中可以看到,没有对话动作。我尝试将其插入,但没有用。我看到那里有一个卡对象,我尝试对其进行操作,但这也不起作用。一些帮助,将不胜感激!

Where i plugged the lambda hook in

我无法让该卡显示在客户端中。以下是event.res:

{
  type: 'PlainText',message: '[User Input: "best offer",Source: ElasticSearch] These are some of our most popular offers:',session: {
    qnabot_qid: 'TelcoBot.005',qnabot_gotanswer: true,qnabotcontext: { prevIoUs: [Object],navigation: [Object] },appContext: { altMessages: {} }
  },card: { send: false,title: '',text: '',url: '' },_userInfo: {
    InteractionCount: 2,UserId: 'eu-west-1:bdd6c35c-8f6f-4b83-90bc-b8b9ae3a9605',FirstSeen: 'Wed Oct 07 2020 04:38:23 GMT+0000 (Coordinated Universal Time)',LastSeen: 'Wed Oct 07 2020 04:45:08 GMT+0000 (Coordinated Universal Time)',TimeSinceLastInteraction: 405.067,isverifiedIdentity: 'false'
  },got_hits: 1,result: {
    qid: 'TelcoBot.005',quniqueterms: ' What are your best offers? Best Offers Popular offers tell me your best offers help me with best offers  ',questions: [ [Object],[Object],[Object] ],a: '[User Input: "best offer",l: 'arn:aws:lambda:eu-west-1:418746351551:function:qna-telco-bestoffer-lambda',args: [ 'BestOffer' ],type: 'qna',answersource: 'ElasticSearch',autotranslate: { a: true },lambdahooks: [ [Object],[Object] ]
  },plainMessage: '[User Input: "best offer",answerSource: 'ELASTICSEARCH'
}
2020-10-07T04:45:08.502Z 

以下是运行lambda之后的event.res,它清楚地表明它正在工作...:

{
    "type": "PlainText","message": "Revised biznatches","session": {
        "qnabotcontext": {
            "prevIoUs": {
                "qid": "TelcoBot.005","a": "[User Input: \"best offer\",Source: ElasticSearch] These are some of our most popular offers:","alt": {},"q": "best offer"
            },"navigation": {
                "next": "","prevIoUs": [],"hasParent": true
            }
        },"appContext": {
            "altMessages": {}
        },"qnabot_qid": "TelcoBot.005","qnabot_gotanswer": true
    },"card": {
        "send": true,"version": 1,"contentType": "application/vnd.amazonaws.card.generic","genericAttachments": [
            {
                "title": "card-title","subTitle": "card-sub-title","imageUrl": "https://en.wikipedia.org/wiki/Image#/media/File:Image_created_with_a_mobile_phone.png","attachmentLinkUrl": "https://en.wikipedia.org/wiki/Image#/media/File:Image_created_with_a_mobile_phone.png","buttons": [
                    {
                        "text": "button-text","value": "Value sent to server on button click"
                    }
                ]
            }
        ]
    },"_userInfo": {
        "UserId": "eu-west-1:bdd6c35c-8f6f-4b83-90bc-b8b9ae3a9605","InteractionCount": 1,"isverifiedIdentity": "false","TimeSinceLastInteraction": 1602002303.774,"FirstSeen": "Wed Oct 07 2020 04:38:23 GMT+0000 (Coordinated Universal Time)","LastSeen": "Wed Oct 07 2020 04:38:23 GMT+0000 (Coordinated Universal Time)"
    },"got_hits": 1,"result": {
        "qid": "TelcoBot.005","quniqueterms": " What are your best offers? Best Offers Popular offers tell me your best offers help me with best offers  ","questions": [
            {
                "q": "What are your best offers?"
            },{
                "q": "Best Offers"
            },{
                "q": "Popular offers"
            },{
                "q": "tell me your best offers"
            },{
                "q": "help me with best offers"
            }
        ],"l": "arn:aws:lambda:eu-west-1:418746351551:function:qna-telco-bestoffer-lambda","args": [
            "BestOffer"
        ],"type": "qna","answersource": "ElasticSearch","autotranslate": {
            "a": true
        },"lambdahooks": [
            {
                "args": []
            },{
                "l": "arn:aws:lambda:eu-west-1:418746351551:function:qna-telco-bestoffer-lambda","args": [
                    "BestOffer"
                ]
            }
        ]
    },"plainMessage": "[User Input: \"best offer\","answerSource": "ELASTICSEARCH"
}

这是函数

exports.handler = (event,context,callback) => {
    event.res.message = "Revised message";
    event.res.card = {
      "send": true,"genericAttachments": [
          {
             "title":"card-title","subTitle":"card-sub-title","imageUrl":"https://en.wikipedia.org/wiki/Image#/media/File:Image_created_with_a_mobile_phone.png","attachmentLinkUrl":"https://en.wikipedia.org/wiki/Image#/media/File:Image_created_with_a_mobile_phone.png","buttons":[ 
                 {
                    "text":"button-text","value":"Value sent to server on button click"
                 }
              ]
           },] 
     };

  callback(null,event);
};

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。