使用机器人

时间:2016-08-03 09:27:05

标签: bots botframework botbuilder

我正在使用 Microsoft BotFramework 开展 Bots 项目我用来显示一些视频文件。在这里,我面临的问题是,当我在本地Bot Frame工作模拟器中运行我的项目时,它每次都正确地获取数据并且我正在配置我的Bot到Skype Channel它正常工作,当我第二次使用它时没有得到数据有时,有时它只获得数据,只有一个视频文件只是第一个视频文件。 有没有适合每次获取完整数据的解决方案? 为此,我在我的方法

中写下面的代码行
Activity replyToConversation = message.CreateReply("Welcome to **My Bot**." + "(Hi)");
        replyToConversation.Recipient = message.From;
        replyToConversation.Type = "message";
        replyToConversation.Attachments = new List<Attachment>();
        Dictionary<string, string> cardContentList = new Dictionary<string, string>();
        cardContentList.Add("Jason Bourne", "");
        cardContentList.Add("The Land", "");
        cardContentList.Add("Yoga Hosers", "");
        foreach (KeyValuePair<string, string> cardContent in cardContentList)
        {
            if (cardContent.Key == "Jason Bourne")
            {
                replyToConversation.Attachments.Add(new Attachment()
                {
                    ContentUrl = "https://ht39ea-bn1306.files.1drv.com/y3mz35iB6o_EJVzJvmSQz9_jNz5Cmpk33LgbGJQjpoZvQaBXrABBDvHrOS5gdHvqh_MIlJoFBIujrSkhkCGRnApldRbmT6W61NTEyOulUGUZtge9hRyKKvh9BHT-VYV_opRLSMnHt7g3b3IaiTNKcjZqQ/Jason%20Bourne%20Official%20Trailer%20%231%20(2016",
                    Name = "Jason Bourne"
                                      });
            }
            else if (cardContent.Key == "The Land")
            {
                replyToConversation.Attachments.Add(new Attachment()
                {
                    ContentUrl = "https://ht39ea-bn1306.files.1drv.com/y3mGspCfSmGDdvQjKK_3UcUIdnZRsAC2jRgHesmL61sIV_zc9F9UQQIWkyHE5E4t6r4T56aWKDQSfN-qduP2VJbiH0rYZ4Ce5DLI2U1DKx-4Tv4UB4OL2Egtk_-BWAow0fC4wf7HCC2ypyQ2dIXrs1hsw/The%20Land%20Official%20Trailer%201%20(2016",

                    ContentType = "video/mp4",
                    Name = "The Land"
                });
            }
            else if (cardContent.Key == "Yoga Hosers")
            {
                replyToConversation.Attachments.Add(new Attachment()
                {
                    ContentUrl = "https://ht39ea-bn1306.files.1drv.com/y3mThBzywEPjMFSh2rdNldHPW1oxtzVTXyrhLrJOp_ACh2YPLQcuw5W-MaSB_5DBJluNXJpvwWBcoWKcQO6Ijx7dWcj2MqHA2uFvvbH6h7mPKsiBhDuC8j5I4_qi-ZsdMuM2G6ztoUtAsdRV0pla-aOGQ/Yoga%20Hosers%20TRAILER%20(2016",

                    ContentType = "video/mp4",
                    Name = "Yoga Hosers"
                });
            }
        }
        replyToConversation.AttachmentLayout = AttachmentLayoutTypes.List;
        await context.PostAsync(replyToConversation);

1 个答案:

答案 0 :(得分:0)

两个问题。首先,“Jason Bourne”项目缺少ContentType字段,因此帖子被拒绝。其次,所提供的链接似乎无效或公开。如果我添加ContentType字段并交换它可以找到的链接。

 Activity replyToConversation = message.CreateReply("Welcome to **My Bot**." + "(Hi)");
        replyToConversation.Recipient = message.From;
        replyToConversation.Type = "message";
        replyToConversation.Attachments = new List<Attachment>();
        Dictionary<string, string> cardContentList = new Dictionary<string, string>();
        cardContentList.Add("Jason Bourne", "");
        cardContentList.Add("The Land", "");
        cardContentList.Add("Yoga Hosers", "");
        foreach (KeyValuePair<string, string> cardContent in cardContentList)
        {
            if (cardContent.Key == "Jason Bourne")
            {
                replyToConversation.Attachments.Add(new Attachment()
                {
                    ContentUrl = "http://www.sample-videos.com/video/mp4/240/big_buck_bunny_240p_1mb.mp4",
                    ContentType = "video/mp4",  // NEW LINE
                    Name = "Jason Bourne"
                });
            }
            else if (cardContent.Key == "The Land")
            {
                replyToConversation.Attachments.Add(new Attachment()
                {
                    ContentUrl = "http://www.sample-videos.com/video/mp4/240/big_buck_bunny_240p_1mb.mp4",

                    ContentType = "video/mp4",
                    Name = "The Land"
                });
            }
            else if (cardContent.Key == "Yoga Hosers")
            {
                replyToConversation.Attachments.Add(new Attachment()
                {
                    ContentUrl = "http://www.sample-videos.com/video/mp4/240/big_buck_bunny_240p_1mb.mp4",

                    ContentType = "video/mp4",
                    Name = "Yoga Hosers"
                });
            }
        }
        replyToConversation.AttachmentLayout = AttachmentLayoutTypes.List;