I made a telegram bot with @botfather and promoted the bot as admin of the public group. Whenever I try to send a message from the python code, it always sends the message to itself, I mean in the private chat and not in the public group.
Snapshot of the code written:
bot_token = 'XXXXXXXXXXXXXXXXXXX'
bot_chatID = '395014927'
bot_message = "Testing"
send_text = 'https://api.telegram.org/bot' + bot_token + '/sendMessage?chat_id=' + bot_chatID + '&text=' + bot_message
response = requests.get(send_text)
response.json()
How can I make the bot to send the message in the group, not to itself?
Am I missing something here or do I need to modify some settings?
EDIT(Solved) : Chat group is always a negative number. Look for that number to get the chat id of that group.
You should send message to the group chat_id
. It seems you are sending message to your bot itself or yourself. why? because chat_id
of group or supergroup starts with -
negative sign. for example : -1001331798505
is chat_id
of my supergroup.
"ok": true,
"result": [{
"update_id": 751829615,
"message": {
"message_id": 5968,
"from": {
"id": 223110107,
"is_bot": false,
"first_name": "\u011e\u0105me",
"last_name": "\u01fever!",
"username": "GameO7er",
"language_code": "en"
},
"chat": {
"id": -257326110,
"title": "This group is not Super Group",
"type": "group",
"all_member s_are_administrators": true
},
as you can see type:group
and this is an example of supergroup
{
"ok": true,
"result": [{
"update_id": 751829616,
"message": {
"message_id": 141,
"from": {
"id": 223110107,
"is_bot": false,
"first_name": "\u011e\u0105me",
"last_name": "\u01fever!",
"username": "GameO7er",
"language_code": "en"
},
"chat": {
"id": -1001241538300,
"title": "this groups is supergroup",
"type": "supergroup"
},
"date": 1568644531,
"text": "A"
}
}]
}
as you can see type:supergroup
if you don't know how get ID of your groups you can read this link