I’m creating a telegram bot using Botogram, but it doesn’t matter. I would like to ask how can i send in a message (using 'bot.api.call')
some values into 'orari ufficiosi'
. I can’t use a for loop otherwise the message will be sent many times. I would like to send a message: I prossimi pullman sono alle: 8.24, 9.07, 11.22, 13.24, 18.13, 19.14
if len(htpr) > 0:
alert1 = "I prossimi pullman sono alle: "
orari_ufficiosi = []
for rfdr in htpr:
if allhdr[allhr.index(str(rfdr))] != "0":
orari_ufficiosi.append(rfdr)
print(orari_ufficiosi)
bot.api.call('sendMessage', {
'chat_id': chat_id,
'text': alert1 + orari_ufficiosi})
I’ve tried to put ‘str(orari_ufficiosi)’, but here is the result
3
Answers
You can do it with a for loop without sending the message many times, just make sure that the message sending is outside of the for loop. You’re already calling the bot API correctly this way, it’s just your print statement which is erroneously inside the for loop. Simply remove two indentation steps from the print and it should look fine.
simply use this :
That should work.