Do not use a token in more than one configuration node at the same time as the telegram server does not allow multiple connections for one bot

What does this mean?

Only one telegram bot in one flow?
Only same telegram bot in one flow?
Only one and same telegram bot in one flow?

I ask this because I have same telgram bot in mutiple flows and I get sometimes polling error. It disapears when re-debloy telegram bot node

Only one source can run a Telegram bot.

So, for example, say you were running Node-RED on two different Pi's. You set up Telegram on each and copy the config from one to the other. Now you have two bot sources trying to control the same Telegram bot and this will fail.

If you need to run a bot from more than one source, you need to set up 1 bot for each source.

Within a single instance of Node-RED, each bot is run by a single configuration node and as many flows/nodes as you like can use that config node so that you can do lots of things with the bot. You can, of course also set up and use multiple bots from within a single instance of Node-RED.

Thank you for your fast reply.
I'm running NR in one RPi and using same telegram bot token in different flows.
You say that this is ok?

Why I then still get this polling error message?

Personally, and it seemed to stop some problems I was getting with missed messages, I only use one flow to send messages to my Telegram Bot. The assembly of a message is done in several flows to suit each purpose and then this is link out / link in to a single instance of the Telegram sender node. This way I can be sure that to Telegram, there is only one connection.

Yes, that is fine. I've done multi-telegram flows across multiple devices using a bot for each device.

Most likely problem would be a network issue.

Well, I don't think I've ever had any issues. However, these days I also tend to have a single in/out point, this has the added advantage that you can control the throughtput and do any sanitising/reformatting all in 1 place.

I use MQTT messages to deal with this as it lets me move to a single bot across as many devices/instances as I like.

The top function node contains this:

let contentType = msg.contentType || 'message'
let mode = msg.mode || 'MarkdownV2' //'Markdown' // 'html'
let content = ''

// Make topic into a pseudo heading (Bold, Underline)
if (msg.topic)   content += `__*${msg.topic.replace(/_/g, ' ')}*__\n`

// Allow complex payload, convert to Markdown
let sp
if (msg.payload) {
    sp = msg.payload
    
    // If payload is an array, assume an array of strings, otherwise try to turn into a string
    if (!Array.isArray(sp)) {
        // Try toString first
        try {
            sp = sp.toString()
        } catch (e) {}
        // Check if it is now `[object Object]`, if it is, try to JSON stringify it instead
        if ( sp === '[object Object]' ) {
            try {
                sp = JSON.stringify(msg.payload)
                // TODO: Maybe newline on comma and [ or { ? Maybe also make json props into bold or italic?
            } catch (e) {
                node.warn(`Cannot convert input payload to a string. ${e.message}`)
                return
            }
        }
        
        // If payload is a string, split on `<br>`
        if (typeof sp === 'string') sp = sp.split('<br>')
    }
    
    // If payload is an array, each element is a new line
    if (Array.isArray(sp)) content += sp.join('\n')
    else if (typeof sp === 'string') content += sp  // belt and braces
}

// If content contains `.` - mode must be Markdown, not MarkdownV2!
if (mode === 'MarkdownV2') {
    if ( /[.{]/.test(content) ) mode = 'Markdown'
}

msg.payload = { 
    "chatId": msg.chatId,
    "content": content,
    "type": contentType,
    "options": { 
        "parse_mode": mode,
    },
}
return msg;

/**
 * Markdown V2 Styles - https://core.telegram.org/bots/api#markdownv2-style
 * 
 * *bold \*text*
 * _italic \*text_
 * __underline__
 * ~strikethrough~
 * *bold _italic bold ~italic bold strikethrough~ __underline italic bold___ bold*
 * [inline URL](http://www.example.com/)
 * [inline mention of a user](tg://user?id=123456789)
 * `inline fixed-width code`
 * ```
 * pre-formatted fixed-width code block
 * ```
 * ```python
 * pre-formatted fixed-width code block written in the Python programming language
 * ```
 * 
 */

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.