简体   繁体   English

在 Telegram 中显示自定义负载

[英]Display Custom Payload in Telegram

I am sending a custom payload to DialogFlow and I want it to be displayed in Telegram.我正在向 DialogFlow 发送自定义有效负载,我希望它显示在 Telegram 中。 When I send just a text response Telegram can display it but it cannot display a custom payload.当我只发送文本响应时,Telegram 可以显示它,但它不能显示自定义有效负载。 This is what I get in the fulfillment response in DialogFlow:这是我在 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?如何让它在 Telegram 中显示?

For you to display the custom payload in telegram, you should follow the payload structure as mentioned in Dialogflow Telegram integration .要在电报中显示自定义有效负载,您应该遵循Dialogflow Telegram 集成中提到的有效负载结构。

 { "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. parse_mode可以是 Markdown、MarkdownV2 或 HTML 样式。 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.TELEGRAM

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

The bot's reply using the custom payload looks like this:机器人使用自定义有效负载的回复如下所示: 在此处输入图像描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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