首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在C#中使用AWS发送响应卡

如何在C#中使用AWS发送响应卡
EN

Stack Overflow用户
提问于 2020-06-08 07:08:51
回答 3查看 508关注 0票数 11

嗨,我正在amazon上开发一个聊天机器人,我想使用lambda函数发送响应卡,但是如果在关闭响应格式中使用响应卡函数,则会出现空异常的错误。有人能说出解决办法吗?PS我是使用FlowerOrder蓝图创建的尼基。

代码语言:javascript
复制
if (slots[greet] != null) 
        {

            var validateGreet = ValidateUserGreeting(slots[greet]);
            if (validateGreet.IsValid) 
            {
                return Close(sessionAttributes,
                              "Fulfilled",
                              new LexResponse.LexMessage
                              {
                                  ContentType = "PlainText",
                                  Content = String.Format("Hello Kindly choose one option")
                              },
                              new LexResponse.LexResponseCard
                              {
                                  Version = 1,
                                  ContentType = "application/vnd.amazonaws.card.generic",
                                  GenericAttachments =
                                  {
                                  new LexResponse.LexGenericAttachments
                                  {
                                      Buttons =
                                      {
                                         new LexResponse.LexButton
                                         {
                                             Text = "Shop Now",
                                             Value = "Shop Now"
                                         }
                                      },
                                      AttachmentLinkUrl = null,
                                      Title = "Shopping",
                                      SubTitle = "Sub Shopping",
                                      ImageUrl = null
                                  }
                                  }
                              }
                              );
            }

异常:-

2020-06-09 17:31:20:对象引用没有设置为对象的实例。:EVS_Test_Abbar_Lambda_Function.OrderWatchIntentProcessorTest.Process(LexEvent lexEvent,ILambdaContext上下文中的NullReferenceException )在D:\AWS项目\Abbrar Projects\EVS_Test_Abbar_Lambda_Function\EVS_Test_Abbar_Lambda_Function\OrderWatchIntentProcessorTest.cs:line 52 at EVS_Test_Abbar_Lambda_Function.Function.FunctionHandler(LexEvent lexEvent,在D:\AWS \Abbrar Projects\EVS_Test_Abbar_Lambda_Function\EVS_Test_Abbar_Lambda_Function\Function.cs:line 43 at lambda_method(关闭、流、流、LambdaContextInternal )

EN

回答 3

Stack Overflow用户

回答已采纳

发布于 2020-06-10 09:07:22

这是它的解决方案,因为如果您查看JSON的结构,它包含许多模型和列表,每个模型和列表都必须单独处理。

代码语言:javascript
复制
LexResponse.LexResponseCard lexResponseCard = new LexResponse.LexResponseCard();

    List<LexResponse.LexGenericAttachments> ListlexGenericAttachments = new List<LexResponse.LexGenericAttachments>();
    LexResponse.LexGenericAttachments lexGenericAttachments = new LexResponse.LexGenericAttachments();



    List<LexResponse.LexButton> ListlexButton = new List<LexResponse.LexButton>();
    LexResponse.LexButton lexButton = new LexResponse.LexButton();



    lexButton.Text = "Yes Now";
    lexButton.Value = "Yes";
    ListlexButton.Add(lexButton);
    lexGenericAttachments.AttachmentLinkUrl = "Link";
    //lexGenericAttachments.AttachmentLinkUrl = null;
    lexGenericAttachments.Title = "Shopping";
    lexGenericAttachments.SubTitle = "Sub Shopping";
    lexGenericAttachments.ImageUrl = "Link";
    //lexGenericAttachments.ImageUrl = null;
    lexGenericAttachments.Buttons = ListlexButton;



    ListlexGenericAttachments.Add(lexGenericAttachments);



    lexResponseCard.Version = 0;
    lexResponseCard.ContentType = "application/vnd.amazonaws.card.generic";
    lexResponseCard.GenericAttachments = ListlexGenericAttachments;



    return Close(sessionAttributes,
                      "Fulfilled", 
                      new LexResponse.LexMessage
                      {
                          ContentType = "PlainText",
                          Content = String.Format("Hello Kindly choose one option")
                      },
                      lexResponseCard
                      );
票数 2
EN

Stack Overflow用户

发布于 2020-06-15 15:08:41

这可能是你的大写键名。例如,您有ContentType,但它应该是contentType作为camelcase,以小写字母开头。

代码语言:javascript
复制
return Close(sessionAttributes,
    "Fulfilled",
    new LexResponse.LexMessage
    {
        contentType = "PlainText",
        content = String.Format("Hello Kindly choose one option")
    },
    new LexResponse.LexResponseCard
    {
        version = 1,
        contentType = "application/vnd.amazonaws.card.generic",
        GenericAttachments =
        {
                new LexResponse.LexGenericAttachments
                {
                    Buttons =
                    {
                        new LexResponse.LexButton
                        {
                            text = "Shop Now",
                            value = "Shop Now"
                        }
                    },
                    attachmentLinkUrl = null,
                    title = "Shopping",
                    subTitle = "Sub Shopping",
                    imageUrl = null
                }
        }
    }
);
票数 1
EN

Stack Overflow用户

发布于 2020-06-15 23:27:10

只试一张莱克斯反应卡。

代码语言:javascript
复制
    return Close(sessionAttributes,
    "Fulfilled"
    new LexResponse.LexResponseCard
    {
        version = 1,
        contentType = "application/vnd.amazonaws.card.generic",
        GenericAttachments =
        {
                new LexResponse.LexGenericAttachments
                {
                    Buttons =
                    {
                        new LexResponse.LexButton
                        {
                            text = "Shop Now",
                            value = "Shop Now"
                        }
                    },
                    attachmentLinkUrl = null,
                    title = "Shopping",
                    subTitle = "Sub Shopping",
                    imageUrl = null
                }
        }
    }
);
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/62256761

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档