3

I am trying to send to multiple messages within one Webhook call to Dialogflow, which shall be passed to Messenger. Right now my Webhook responds with a malfunctioning JSON body:

{
    'fulfillmentText': "Text",
    'fulfillmentMessages': [{
        "platform": "facebook",
        "text": [{
            "text": "Text"
        }]
    }],
    'source': "facebook"
}

When I test the Webhook via Messenger I see the is typing symbol, but never receive the Text message. While testing the same Webhook from the Dialogflow Console I get

Webhook execution successful

returned. I guess I am missing some JSON fields to tell Dialogflow in which format it has to send the JSON two the Messenger API. Anybody having any clues on how to solve this issue?


Edit: My latest not working trial...

{
  "fulfillmentText": "Hola!",
  "fulfillmentMessages": [
    {
      "text": {
        "text": [
          "Title: this is a title"
        ]
      },
      "platform": "FACEBOOK"
    },
    {
      "text": {
        "text": [
          "Title: this is a title"
        ]
      },
      "platform": "FACEBOOK"
    }
  ]
}
DrDirk
  • 1,937
  • 3
  • 25
  • 36

2 Answers2

4

If you're only sending text you only need to provide a string to the fulfillmentText and don't have to provide the fulfillmentMessages attribute.

If you do provide a fulfillmentMessages attribute with the target platform Dialogflow will send your payload to Facebook. In this case, where the payload is invalid, no message will actually be surfaced in Facebook. remove the fulfillmentMessages attribute of the response JSON and your bot should respond.

If you'd like to add a card to your response you can send the following response:

{
  "fulfillmentMessages": [
    {
      "platform": "FACEBOOK",
      "card": {
        "title": "Title: this is a title",
        "subtitle": "This is an subtitle.  Text can include unicode characters including emoji .",
        "imageUri": "https://developers.google.com/actions/images/badges/XPM_BADGING_GoogleAssistant_VER.png",
        "buttons": [
          {
            "text": "This is a button",
            "postback": "https://assistant.google.com/"
          }
        ]
      }
    }
  ]
}


EDIT: If you want to send multiple messages you can do so by sending a response like this (this JSON will send two identical cards but you can change the message type (card/text/etc) based on this documentation):
{
  "fulfillmentMessages": [
    {
      "platform": "FACEBOOK",
      "card": {
        "title": "Title: this is a title",
        "subtitle": "This is an subtitle.  Text can include unicode characters including emoji .",
        "imageUri": "https://developers.google.com/actions/images/badges/XPM_BADGING_GoogleAssistant_VER.png",
        "buttons": [
          {
            "text": "This is a button",
            "postback": "https://assistant.google.com/"
          }
        ]
      }
    },
    {
      "platform": "FACEBOOK",
      "card": {
        "title": "Title: this is a title",
        "subtitle": "This is an subtitle.  Text can include unicode characters including emoji .",
        "imageUri": "https://developers.google.com/actions/images/badges/XPM_BADGING_GoogleAssistant_VER.png",
        "buttons": [
          {
            "text": "This is a button",
            "postback": "https://assistant.google.com/"
          }
        ]
      }
    }
  ]
}
mattcarrollcode
  • 3,429
  • 16
  • 16
  • Yes that is what I’m doing right now. But I want to send multiple messages, which I can also do within the dialogflow console while adding text responses. – DrDirk Dec 06 '17 at 19:20
  • Actually your edit represents exactly what I am doing! Instead of using a Card I am using a text object, but Dialogflow does not respond. I posted my doing as an edit. Could you check if you see any errors? If not I am pretty sure the fault is on Dialogflows side! – DrDirk Dec 07 '17 at 12:01
2

I mailed the Dialogflow support about this issue and it turns out that it is currently not possible to send multiple messages from a webhook.

Hi,

At this point, it's not possible to send sequential messages directly from webhook. However, if you are using one of our one-click integrations that support rich messages, you can invoke intents in which multiple messages are defined from webhook through an event as described at https://dialogflow.com/docs/events#invoking_event_from_webhook.

Let me know if you have any questions.

Regards, Ankita from Dialogflow

DrDirk
  • 1,937
  • 3
  • 25
  • 36