What could go wrong in telegram bot alert?

what could be reason of this error?

{"ok":false,"error_code":400,"description":"Bad Request: chat not found"}
where my written code in python file is :

  1. send telegram message function

def send_telegram_message(message):
‘’‘sends message via telegram’’’
print(“This is the telegram response”)
return telegram_data[“ok”]
except Exception as e:
print(“An error occured in sending the alert message via telegram”)
return False

  1. main function which runs the program

while True:
# Step 1
print("Current sensor value is ", str(temp))
# Step 2
if sensor_value == -999 :
print(“Request was unsuccessful. Skipping!”)
# Step 3
if sensor_value >= conf.threshold:
print(“Sensor value has exceeded threshold”)
message="Alert! Sensor value has exceeded " + str(conf.threshold) + "The current value is " + str(temp)
print(“This is the telegram status:”,telegram_status)
# Step 4

1 Like

Hey @kamramohit96 ,

Most Probably the error resides in your configuration i.e. in your telegram chat id and bot id. Check it once and make sure it matches your correct data.

1 Like

Yes this was the reason I was using channel name instead of channel id thanks

sir can u please help me the same in this telegram conf.py file

how to know channel id

I’m facing the same challenge, can someone help to clarify how to get the Telegram Channel ID. Is the invite link is equal to channel ID ? which being with t.me/XXXXX… Should this be added as telegram_chat_id = ‘@t.me/XXXXX’, please confirm.

Hey Hi @majidmkk
In your case plz remove that ‘t.me/’ and use as
telegram_chat_id =’@xxxx’ and try it.
Hope this helps!!

For me also same error.I have checked my chat id and bot id many times.Actually I am confused from distinguishing between Capital ‘O’ and zero in bot id.Please help me.

To get the channel id or pretty much any id on telegram…just type something in the channel…Then forward it to “@getidsbot” …this bot will give your id along with the channel id …which should be negative 100 followed by 13 digits. …do not put this in front of the @…this is for not using the @

Channel id’ is the id name that you have provided in your invite link
Here I’ve attached my channel that i creates, the highlighted one is the ‘channel id’ that is to be provided for receiving the alert message… This can clear out the ‘400:Chat not found’ error!!

Here channel id will be…"@temp3alert"

Hope This Helps!!:smile: