Botframework V4:Messenger上的视频附件

时间:2019-02-18 03:11:06

标签: c# botframework messenger video-card

嗨,我尝试了所有将视频附加到漫游器的方法。它们都在bot模拟器中正常运行。但是当我将其发布给Messenger时,它抛出了异常。 (由于出现消息,我无法以我只知道的方式看到异常。是否有办法查看或记录异常?)。 Messenger中不支持视频卡吗?还是不支持youtube作为网址链接?

以下是代码:

# Python Output:-

---- One:
defaultdict(<class 'dict'>,
            {'MC1': {123: '-15,-15C',
                     287: '-12,-12C',
                     391: '-19,-19C',
                     456: '5,5C'}})
---- Two:
{}
---- Three:
{123: '-15,-15C', 287: '-12,-12C', 391: '-19,-19C', 456: '5,5C'}
---- Four:
'-19,-19C'
Traceback (most recent call last):
  File "C:\Projects\00-Development\LXQuery\CDB-Review\dict.py", line 30, in <module>
    xdata["MC1"][123]["PP"] = "-15,-15C"  # ERROR: Key error 123
KeyError: 123

     AddStep(async (stepContext, cancellationToken) =>
        {
            var reply = stepContext.Context.Activity.CreateReply();
            reply.Attachments = new List<Attachment>();
            reply.Attachments.Add(GetVideoCard().ToAttachment());
            await stepContext.Context.SendActivityAsync(reply, cancellationToken);
            return await stepContext.NextAsync();
        });

////////////////

   private static VideoCard GetVideoCard()
    {
        var videoCard = new VideoCard
        {
            Title = "Budgeting Introduction",
            Subtitle = "by Finko",

            Media = new List<MediaUrl>
            {
                new MediaUrl()
                {
                    Url = "https://www.youtube.com/watch?v=XLo1geVokhA",
                },
            },
            Buttons = new List<CardAction>
            {
                new CardAction()
                {
                    Title = "Learn More at Finko.PH",
                    Type = ActionTypes.OpenUrl,
                    Value = "https://m-moreno.wixsite.com/finkoph?fbclid=IwAR1NVtlyKfzZ0mYFIWva8L-d8TUv4KFpt_m1i1ij3raT-pbWr2c3-kqzB2Q",
                },
            },
        };

        return videoCard;
    }

    AddStep(async (stepContext, cancellationToken) =>
        {
            var activity = stepContext.Context.Activity;
            await stepContext.Context.SendActivityAsync(CreateResponse(activity, CreateVideoCardAttacment()));
            return await stepContext.NextAsync();
        });

////////////////////////

   private Activity CreateResponse(Activity activity, Attachment attachment)
    {
        var response = activity.CreateReply();
        response.Attachments = new List<Attachment>() { attachment };
        return response;
    }

    private Attachment CreateVideoCardAttacment()
    {
        return new VideoCard()
        {
            Title = "Are you a Seafarer? OFW? FREE PERSONAL FINANCIAL ADVICE HERE!!",
            Media = new List<MediaUrl>()
            {
                new MediaUrl("https://www.youtube.com/watch?v=XLo1geVokhA")
            },
            Buttons = new List<CardAction>()
            {
                new CardAction()
                {
                    Type = ActionTypes.OpenUrl,
                    Title = "Learn More at Finko.PH",
                    Value = "https://m-moreno.wixsite.com/finkoph?fbclid=IwAR1NVtlyKfzZ0mYFIWva8L-d8TUv4KFpt_m1i1ij3raT-pbWr2c3-kqzB2Q"
                }
            },
            Subtitle = "by Finko.Ph",
            Text = "Are you tired of getting bogus financial advice? Tired of having 'kape' just to find out it was networking, or a pyramid scheme? Tired of scouring the internet for HOURS but not finding what you're looking for? We're here to help! We give financial advice and will educate you on financial literacy topics, ABSOLUTELY FREE!!"
        }.ToAttachment();
    }

       Activity reply = stepContext.Context.Activity.CreateReply();
            var card = new VideoCard
            {
                Title = "Finko.ph",
                Media = new List<MediaUrl>()
                {
                    new MediaUrl("https://www.youtube.com/watch?v=XLo1geVokhA")
                },
                Buttons = new List<CardAction>()
                {
                    new CardAction()
                    {
                        Type = ActionTypes.OpenUrl,
                        Title = "Learn More at Finko.PH",
                        Value = "https://m-moreno.wixsite.com/finkoph?fbclid=IwAR1NVtlyKfzZ0mYFIWva8L-d8TUv4KFpt_m1i1ij3raT-pbWr2c3-kqzB2Q"
                    }
                },
            };
            reply.Attachments.Add(card.ToAttachment());
            await stepContext.Context.SendActivityAsync(reply);
            return await stepContext.NextAsync();

所有这些代码都可以在漫游器模拟器中运行,但不能在Messenger中运行。任何帮助将不胜感激,谢谢。

1 个答案:

答案 0 :(得分:0)

BotFramework将视频卡转换为Facebook Messenger的媒体模板,并且根据Facebook的Developer文档,媒体模板不允许任何外部URL,仅允许Facebook上的外部URL。您必须将视频上传到Facebook或直接提供指向mp4文件的URL,不幸的是,YouTube无法提供该URL。

有关更多详细信息,请参阅有关Media Templates的Facebook文档。