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’’’
url=“http://api.telegram.org/"+conf.telegram_bot_id+"/sendMessage
data={
“chat_id”:conf.telegram_chat_id,
“text”:message
}
try:
response=requests.request(
“POST”,
url,
params=data
)
print(“This is the telegram response”)
print(response.text)
telegram_data=json.loads(response.text)
return telegram_data[“ok”]
except Exception as e:
print(“An error occured in sending the alert message via telegram”)
print(e)
return False

  1. main function which runs the program

while True:
# Step 1
sensor_value=get_sensor_value_from_pin(“A0”)
temp=float(sensor_value)//10.24
print("Current sensor value is ", str(temp))
# Step 2
if sensor_value == -999 :
print(“Request was unsuccessful. Skipping!”)
time.sleep(30)
continue
# 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)
telegram_status=send_telegram_message(message)
print(“This is the telegram status:”,telegram_status)
# Step 4
time.sleep(30)

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