node-red-contrib-chatbot icon indicating copy to clipboard operation
node-red-contrib-chatbot copied to clipboard

Image + HTML caption + Buttons

Open mu3 opened this issue 5 years ago • 5 comments

I'd like to send an image with html-formated caption and actionable buttons:

Screen Shot 2020-05-21 at 20 56 20

Using node-red-contrib-telegrambot it is possible to achieve with the following payload:

{
  "chatId": 123,
  "type": "photo",
  "content": "https://...jpg",
  "caption": "<b>Tony Vespa</b>\n<a href=\"https://...\">link</a>",
  "options": {
    "parse_mode": "HTML",
    "reply_markup": {
      "inline_keyboard": [
        [{ "text": "⭐️", "callback_data": "rate 1" }]
      ]
    }
  }
}

So I've adopted it for the RedBot:

{
  "chatId": msg.originalMessage.chatId,
  "type": "photo",
  "content": "https://...jpg",
  "caption": "<b>Tony Vespa</b>\n<a href=\"https://...\">link</a>",
  "params": { "parseMode": "HTML" },
  "buttons": [{
    "type": "postback",
    "label": "⭐️",
    "value": "1",
    "answer": "Rated: ⭐️",
    "alert": false,
    "style": ""
  }]
}

Seems that type must be set to message (for html formatting), photo or inline-buttons but not combined.

mu3 avatar May 21 '20 17:05 mu3

I recently added the params node which allows to set the parse mode (for telegram) for every type of messages

guidone avatar Jun 19 '20 09:06 guidone

Oh thanks! Is there a way to combine photo with buttons?

mu3 avatar Jun 19 '20 12:06 mu3

yes just chain them

receiver -> photo block -> text block -> sender block

https://github.com/guidone/node-red-contrib-chatbot/wiki/Changes-0.19.0

guidone avatar Jun 19 '20 12:06 guidone

Chaining Conversation > Image > Buttons > Sender generates the following msg.payload:

[{
  "type": "photo",
  "content": buffer[78045],
  "filename": "image.png",
  "mimeType": "image/png",
  "caption": "tony",
  "chatId": "******",
  "messageId": null,
  "inbound": false
}, {
  "type": "inline-buttons",
  "name": null,
  "content": null,
  "chatId": "******",
  "messageId": null,
  "buttons": [{
    "type": "postback",
    "label": "⭐️",
    "value": "1",
    "answer": "Rated ⭐️",
    "alert": false,
    "style": ""
  }]
}]

And only the first item is sent. I want to combine them:

"type": "photo",
"buttons": [...]

mu3 avatar Jun 19 '20 14:06 mu3

Ok, I think it's technically possible

https://core.telegram.org/bots/api#sendphoto

Telegram allows to add buttons to every type of message, the problem is that other platforms don't, so I have to come up with something that doesn't break the compatibility with other platforms and it's not too specific.

Let me think about it

guidone avatar Jun 22 '20 06:06 guidone