ebeneditos / telegram.bot

Develop a Telegram Bot with R
https://ebeneditos.github.io/telegram.bot/
GNU General Public License v3.0
107 stars 24 forks source link

Error in private$request(url, data) :Bad Request (HTTP 400). #18

Closed ilsafaust closed 2 years ago

ilsafaust commented 2 years ago

Please choose one of the following and fill the appropriate field:

Bug Report (or a question)

I'm trying to send message from Bot for a chat_id's from the array (df$telegram_id). Sometimes I get the following error:

private$request(url, data) :Bad Request (HTTP 400).

I suppose that this is because of some private settings of some chats. If there are only chat_id's in the array that can receive messages from Bot everything is ok.

Could you please help how I can skip the chat_id's with this error?

The function for sending message is below:

send_messages <- function(df) {

for (k in 1:nrow(df)) {

updater$bot$sendMessage(parse_mode = "Markdown", chat_id = df$telegram_id[k], text = df$message[k])

}

}

ebeneditos commented 2 years ago

You could do a tryCatch to detect those errors and define an action when that happens. There is an example here, but you can find other examples on the net. Closing the threat as this is not package related, hope it helped though.

krose commented 2 years ago

Just to chip in. @ilsafaust Perhaps you run into the character limit at something near 4K characters, so some messages might need to be split up.