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}));