Data not predictably received in skype using bots

2019-06-01 10:35发布

问题:

I am working on Bots Project using Microsoft BotFramework, in that I am using to display some video files. Here I am facing the issue is when I am running my project in local Bot Frame work Emulator its getting the data properly at every time and I am configuring my Bot to Skype Channel its working first time properly and when I am using the second time it’s not getting the data some times and sometimes it’s getting data like only one video file that is nothing but first video file. Is there any proper solution for getting the complete data every time? For this I am write the below line of code in my method

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:

Two issues. First, the"Jason Bourne" item is missing the ContentType field so the post is being rejected. Secondly the links provided don't seem to be valid or publicly available. If I add the ContentType field and swap out the links it works find.

 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;