Telegram bot /getUpdates does not contain data - telegram

I have a bot that I have added to a group. I messages the group to get the group ID from the following:
https://api.telegram.org/bot1856444417:AAH4vG6lkAbFNkM41e4444k-3s42f0-abgs/getUpdates
but I just get the result:
{"ok":true,"result":[]}
I have tried removing the bot and re-addng it and I have tried # the bot but neither gives me a result.
When I originally created the bot I was able to get an ID from a chat I had with it directly but now even that has stopped working.
This method of getting the chatID seems so flakey. Am I doing something wrong or is there any other way to get the chatid?

For anyone having this issue, it is because your bot have the Privacy Group mode enabled.
On BotFather chat, list your created bots and select the respective bot where you to change the Group Privacy setting. Turn it off and there you go, now the result array from Telegram API will be properly displayed.

I got around this by creating another bot, adding it to the group, getting the ID from it and then deleting it.

Use getMe instead of getupdates. It worked for me.

Related

How to get topic id for telegram group chat?

Recently Telegram added support for Topics in Groups in Bot API version 6.3 and this support added into python-telegram-bot version 13.15 (please find changelog https://docs.python-telegram-bot.org/en/stable/changelog.html)
It's not clear how to get a Topic ID (message_thread_id) for topics in Grpups where topics enabeled.
Any suggestion?
I'm trying to find a way how to get topic id for telegram group chats. Please be aware that I talking about message_thread_id, please do not confuse with chat_id.
You can try to get the message_thread_id from the message link
send a message to the topic you need from the application
right click on the sent message and choose "Copy message link"
paste link somewhere
you will see something like this: https://t.me/c/1112223334/25/33
the value 25(value after long number) from the link will be message_thread_id
I assume that -100 + 1112223334 - will be equal chat_id
The number after will be message_thread_id
And the last one should be message_id

Get telegram group ID

At first i should emphasis that this is a question about telegram GROUP NOT CHANNEL.I need to get group id to send message via telgram api.
I have review this link .
using #rawDataBot needs to add bot to group, that is not possible most of the times. CuteGram does not login (does not send login code) .so i can say none of the proposed method works.
so is there a new method -except adding a bot to the group- to get telgram group ID ?
if the answer is no, i need to know if it is possible to send message to group by using group name?!
the easiest way is to add #chatBotRaw the bot will dump raw data, and you can copy their chat_id or anything else you need,
Remember to remove the bot afterwards because it dumps raw data of every message sent/received in the group.
the simplest way i found is
open web-telegram in a browser
right click on the group name on the left menu
click 'inspect' button
you will see the group id in the attribute data-peer-id="-xxxxxxxxxx" or peer="-xxxxxxxxxx"
You can get chat id throw object "chat"
You can set middleware which handle new update
Example on Node.JS: bot.on('text', ctx => console.log('Chat id is:', ctx.chat.id))
P.S. group id and chat id are same
if using a bot is acceptable, you can use #username_to_id_bot - no need to add it to a group, just send username or invite link and get the id

How can I get message ID in telegram which can be used in t.me URLs in TdApi?

I'm using TdAPi and I want to get the message Id, which combined with the Username gives you the full link, e.g. something like this.
The message id I get right now is something like 161381342160 but I need to get 22.
I'm listening for UpdateNewMessage right now - do I need to check something else?
Please note: this is not a bot, it's a Telegram client program.
Webogram successfully does this but I haven't figured out how it accomplishes that task.
Thank you!

A way to catch if user leave chat teleram bot

i find new_chat_participant or left_chat_participant but that work only in group chat.
I've used the new_chat_members event to know weather a new user joined the bot or not. But seems that this event will not be emitted.
But using the message event I will get the below result:
{"message_id":4,"from":{"id":324299944,"is_bot":false,"first_name":"foo","last_name":"bar","language_code":"en"},"chat":{"id":324299944,"first_name":"foo","last_name":"bar","type":"private"},"date":1513786467,"text":"/start","entities":[{"offset":0,"length":6,"type":"bot_command"}]
i write bot with java script and in the google app script .
my oreginal problem is how to find out a user stop or left the bot
For some reason that I was not able to find in the docs telegram doesn't send updates when user leaves the private group. It only does it for public groups (ex supergroups). Another curious thing is that the update message contains "left_chat_participant" and "left_chat_member" objects with the exact same info, probably for some bc
unfortunately currently there is no way to found out the user block the bot. new_chat_participant or left_chat_participant presented in telegram bot API v3 for completely another purpose.

Get TELEGRAM Channel/Group ID

Let's say, I've joined TELEGRAM group...
I am just a typical member of GROUP (and thus, cant use any bots there.. ?) so, I am unable to find out the way, how to get GROUP ID.
New Update
Just Simply Forward a message from your channel to This Bot: (https://telegram.me/getidsbot)
Update
1: Goto (https://web.telegram.org)
2: Goto your Gorup and Find your link of Gorup(https://web.telegram.org/#/im?p=g154513121)
3: Copy That number after g and put a (-) Before That -154513121
4: Send Your Message to Gorup
bot.sendMessage(-154513121, "Hi")
I Tested Now and Work like a Charm
Node.js:
Try using TelegramBot#getChat():
bot.getChat("#channelusername").then(function(chat) {
// 'chat' is a Chat object
console.log(chat.id);
});
See API getChat() method and Chat object.
Hope that helps.
There is a unofficicl Plus Messenger client for Android users, and you can see ID in group/channel info.
Supergroup and Channel will looks like 1068773197, which is -1001068773197 for bots (with -100 prefix).
If you just want to obtain channel/user ID, forward message to #RawDataBot.
there are lots of ways to do so.
simplest one: download plus messenger which is a fork of telegram. it shows every channel's id in the about page of that channel.
https://play.google.com/store/apps/details?id=org.telegram.plus&hl=en
thanks to #Sean:
Supergroup and Channel will looks like 1068773197, which is -1001068773197 for bots (with -100 prefix).
Above method works for channels, for groups you may use this method:
Just forward a single message from that chat to #RawDataBot. it will reply you with a json data containing chatid.
via code:
If you are a member of a group, you should receive updates from that group when ever there is any activity from that group. The updates will contain a chats list-element from which you can get a Channel which has the following relevant fields:
id: group_id,
title: "the_group_title",
username: "group_username"
As of my experience ,there are two popular libraries,
python-Telethon --->Telegram Client Library(uses api_id,api_hash)
python-Telegram-bot ---->Telegram Bot (uses api token)
There are lot of ways to get the user_id ,group_id,channel_id .
To get the these ids use Telethon client library
from telethon import TelegramClient,sync
api_id="xxx" #get from telegram website
api_hash="yyy" #get from telegram website
client=TelegramClient(session_object,api_id,api_hash)
client.start()
#To get the channel_id,group_id,user_id
for chat in client.get_dialogs():
print('name:{0} ids:{1} is_user:{2} is_channel{3} is_group:{4}'.format(chat.name,chat.id,chat.is_user,chat.is_channel,chat.is_group))
That is all about, it will print name and id of channel,group,user.
Also, it will check wheather the id is belong to channel or group or user
generally, Channel id starts with negrative(eg:-1001109500936) starts with (-100)
group id is normal and starts with negative
user id starts with positve
Another way is to use 'plus messanger app'
To see all the group,channel,user id
Cheers
Another Simple Way,
client=TelegramClient(session,api_id,api_hash)
client.start()
destination_entity_name="Type User(may be bot) or group or channel name"
entity=client.get_entity(destination_entity_name)
print(entity.stringify()) #All paratmeters
print(entity.id) #user(bot also considered as user) or group
That should be obtainable using tg-messenger-cli: https://github.com/vysheng/tg I haven't had time to try it out yet but friend has made some automated messages for his daughter. Should be quite versatile.
After hours spent, I was able to find the ID of GROUPS using CuteGram app.
Open group there, and click "COPY" icon, that opens a folder, and in the address you will see the ID.
Invite your bot to your group
and use ur bot to text /myid
then use the GetUpdates api, you shall have your group ID

Resources