在 Telegram 中显示自定义负载
Display Custom Payload in Telegram
我正在向 DialogFlow 发送自定义负载,我希望它显示在 Telegram 中。当我只发送文本响应时,Telegram 可以显示它,但不能显示自定义负载。这是我在 DialogFlow 的履行响应中得到的:
"fulfillmentMessages": [
{
"payload": {
"messages": [
{
"type": "yellow,
"text": "lorem ipsum"
}
]
},
"platform": "PLATFORM_UNSPECIFIED"
}
],
"outputContexts": []
}
我以这种方式发送负载:
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);
负载看起来像这样:
let payload = {
"messages": [
{
"type": "text",
"text": "Select your favorite food category or send me your location!",
}
]};
如何让它显示在 Telegram 中?
为了在电报中显示自定义负载,您应该遵循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
可以是 Markdown、MarkdownV2 或 HTML 风格。您可以查看 telegram formatting options 了解有关如何设置消息格式的更多详细信息。
同样在您的代码中将代理更改为 agent.TELEGRAM
。
agent.add(new dfff.Payload(agent.TELEGRAM, payload, {sendAsMessage: true, rawPayload: true}));
机器人使用自定义负载的回复如下所示:
我正在向 DialogFlow 发送自定义负载,我希望它显示在 Telegram 中。当我只发送文本响应时,Telegram 可以显示它,但不能显示自定义负载。这是我在 DialogFlow 的履行响应中得到的:
"fulfillmentMessages": [
{
"payload": {
"messages": [
{
"type": "yellow,
"text": "lorem ipsum"
}
]
},
"platform": "PLATFORM_UNSPECIFIED"
}
],
"outputContexts": []
}
我以这种方式发送负载:
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);
负载看起来像这样:
let payload = {
"messages": [
{
"type": "text",
"text": "Select your favorite food category or send me your location!",
}
]};
如何让它显示在 Telegram 中?
为了在电报中显示自定义负载,您应该遵循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
可以是 Markdown、MarkdownV2 或 HTML 风格。您可以查看 telegram formatting options 了解有关如何设置消息格式的更多详细信息。
同样在您的代码中将代理更改为 agent.TELEGRAM
。
agent.add(new dfff.Payload(agent.TELEGRAM, payload, {sendAsMessage: true, rawPayload: true}));
机器人使用自定义负载的回复如下所示: