3

I have a simple bot for ordering pizza, in a fullfilment function, I would like to display a video instead of a message.

Here is what I have so far:

'use strict';

// Close dialog with the customer, reporting fulfillmentState of Failed or Fulfilled ("Thanks, your pizza will arrive in 20 minutes")
function close(sessionAttributes, fulfillmentState, message) {
    return {
        sessionAttributes,
        dialogAction: {
            type: 'Close',
            fulfillmentState,
            message,
        },
    };
}

// --------------- Events -----------------------

function dispatch(intentRequest, callback) {
    console.log(`request received for userId=${intentRequest.userId}, intentName=${intentRequest.currentIntent.name}`);
    const sessionAttributes = intentRequest.sessionAttributes;
    const slots = intentRequest.currentIntent.slots;
    const crust = slots.crust;
    const size = slots.size;
    const pizzaKind = slots.pizzaKind;

    callback(close(sessionAttributes, 'Fulfilled',
    {
    'contentType': 'CustomPayload', 
    'content': `https://meed.audiencevideo.com/videos/glad_hear.mp4`}));

}

// --------------- Main handler -----------------------

// Route the incoming request based on intent.
// The JSON body of the request is provided in the event slot.
exports.handler = (event, context, callback) => {
    try {
        dispatch(event,
            (response) => {
                callback(null, response);
            });
    } catch (err) {
        callback(err);
    }
};

Unfortunately, my function now returns me only link.

John Rotenstein
  • 241,921
  • 22
  • 380
  • 470
The Dead Man
  • 6,258
  • 28
  • 111
  • 193
  • What channel are you trying to output a video to? – Jay A. Little May 16 '19 at 11:47
  • am new to lex what do you mean by saying channel?? – The Dead Man May 16 '19 at 12:04
  • 1
    Sorry, the channels are whatever the user actually interacts with on their end to communicate with your Lex bot, for example: Facebook Messenger, Slack, SMS, a custom web chat, etc. That will determine the answer because how messages like video are displayed to the user is handled by those channels individually, not by Lex. – Jay A. Little May 16 '19 at 12:27
  • I will be using facebook – The Dead Man May 16 '19 at 12:39
  • If I knew for sure I'd give an answer, but I at least know that Facebook Messenger does allow video to be sent as an attachment in their Send API. It is then up to Amazon's built-in channel manager whether it properly packages and sends your video in a way that Facebook will display it as a video or as a link. So you will just have to test in an actual Facebook Messenger channel to find out. Don't use the Lex Test Chat to test this type of thing because it has its own ways of displaying messages. – Jay A. Little May 16 '19 at 12:53
  • 2
    Yep, Amazon says it accepts custom payload in their docs but unfortunately, there is no example which explains how to deal with the video format :( – The Dead Man May 16 '19 at 12:58
  • If you are using facebook messenger, their documentation gives you the format for different content types: https://developers.facebook.com/docs/messenger-platform/send-messages/#url it looks like you will need to use the attaching from URl response. – Dylan May 16 '19 at 14:37
  • 2
    check the format facebook messenger is expecting, and send exactly same in your custom payload. facebook messenger will recognize that format and render it accordingly. – sid8491 May 17 '19 at 06:36

0 Answers0