简体   繁体   中英

Display Custom Payload in Telegram

I am sending a custom payload to DialogFlow and I want it to be displayed in Telegram. When I send just a text response Telegram can display it but it cannot display a custom payload. This is what I get in the fulfillment response in DialogFlow:

"fulfillmentMessages": [
    {
      "payload": {
        "messages": [
          {
            "type": "yellow,
            "text": "lorem ipsum"
          }
        ]
      },
      "platform": "PLATFORM_UNSPECIFIED"
    }
  ],
  "outputContexts": []
}

I am sending the payload in this manner:

const agent = new dfff.WebhookClient({
        request: req,
        response: res
    })
    const demo = async function(agent) {
         //more code
         agent.add(new dfff.Payload(agent.UNSPECIFIED, payload, {sendAsMessage: true, rawPayload: true}));
    }
    let intentMap = new Map();
    intentMap.set('MyIntent', demo);
    agent.handleRequest(intentMap);

This is what payload looks like:

let payload = {
            "messages": [
                {
                    "type": "text",
                    "text": "Select your favorite food category or send me your location!",
                }
            ]};

How can I get it to display inside of Telegram?

For you to display the custom payload in telegram, you should follow the payload structure as mentioned in Dialogflow Telegram integration .

 { "telegram": { "text": "You can read about *telegram docs* [here](https://cloud.google.com/dialogflow/es/docs/integrations/telegram).", "parse_mode": "Markdown" } }

parse_mode can be either Markdown, MarkdownV2 or HTML style. You can check telegram formatting options for more details on how to format messages.

Also on your code change the agent to agent.TELEGRAM .

agent.add(new dfff.Payload(agent.TELEGRAM, payload, {sendAsMessage: true, rawPayload: true}));

The bot's reply using the custom payload looks like this: 在此处输入图像描述

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM