Do bots have chat_id like user accounts? Where can I find it? I want to use it to send messages to my bot using pyrogram.
Chat IDs are the same for everyone that accesses that chat. In private messages (1-to-1 chats), chat_id == user_id.
Two Examples:
The chat_id of #PyrogramChat is -1001387666944, no matter who accesses or retrieves it.
#PyrogramBot has the user_id 483849041, to send it a message you can use that ID as the chat_id.
As for how to send messages, see the Documentation.
Yes they do, bot tokens are in that format - BOT_ID:SOME_STUFF, in here BOT_ID is your bot's id.
Related
I need to tag everybody in chat where my bot added.
My bot writes: #all and it should tag everybody in the chat.
I don't see any Telegram API methods to get all users in specific chat. How should I resolve the problem?
There are various obstacles that don't let you mention everyone in a single message:
You can only have up to 50 mentions in each message. [1]
You cannot fetch a list of all members in a chat using a bot.
If you insist on doing this, you should use a database to collect information about the members of these chats, when they send messages. And afterward, you should send multiple messages to mention all of them 50 by 50.
If you want a simple way to notify all members, you can just pin a message.
I've been using a Telegram BOT to send notifications for a group, and for users.
I already know i can get Chat ID by receiving a message from the user on my bot, using getUpdates.
I also know i can get Group ID using the same method...
But what i really need is:
There is three users in my group.
My bot.
Me.
Another user that didn't sent any messages to my bot so it does not appear on getUpdates
Is it possible to get this third user his ID?
PS: I am the group owner, and also added my bot as Admin...
The third user is a normal user.
Can someone help me?
Thanks!
That's not possible with the offical Telegram Bot API
Possible Workarounds:
Hold a list of your own. If a user is joining (new_chat_member), lefting (left_chat_member), somebody is sending a message in the group, and so on. Check Message for more information.
Check if a user is a member of the group with getChatMember.
Also may be helpful: getChatMembersCount and getChatAdministrators
is there any Telegram bot out there which can send a private message to any member of a Group(where I am not the owner). If not, how would the procedure look like to build one?
That's not possible. For a bot to be able to send a message to a user, the user must have initiated a conversation with the bot first. Moreover, bots can't even get the list of members of groups or channels, especially not private ones (via the bot api).
Is it possible to create a bot who manage more than one conversation with one user?
I need to create a bot able to make the link between a random chat and telegram.
For example, if I don't wont to use Facebook Messenger anymore, creating a bot who send me every new Facebook message from my account to my Telegram number. The bot would create a new conversation for each unique Facebook user sending me message. Or, if it's not possible, a bot who create a new temporary bot for each new user conversation and give me his #name.
Is it possible with the Telegram Bot API?
According to the latest telegram bot api you can make more than one bot, but one thing that is crucial is the bot's API token that is made manually through botFather. You can make a single bot and make other bots inherit its features and every time a new user sends you a message assign a bot to him/her. Up to here, it's possible but for API token all you can do is to make as much bots as your Facebook friends count and store their api tokens in a DB and pass one of the api tokens to the bot that stands for a user.
This is what I think can solve your problem but the api token part is a bit strange 😀 although you can send a notification from the main bot to your own account when the number of unsigned api tokens get less than 5.
As you know the number of Facebook friends can change and any of them at any time can text you so there must be enough tokens because every time one of them texts you for the first time a bot must be created with a pre-made api token and inherit the features from the main bot. From that moment that token and that bot stand for the person who tried to message you.
Also I think there must be a limit to the number of the bots that you
can make using one telegram account which can be solved using
different accounts.
What you want is possible, as you know every single telegram user has a unique chatID in telegram so if your friends or users text to your bot directly you can use a code like below to answer their messages from your own telegram account and make the bot send it to the related user:
if(update.Message.Text != null)
{
var req = new SendMessage(Your_Own_ChatID, "This message is sent from the user with chat ID: "+update.Message.Chat.Id.ToString()+"\n In order to reply it type the user's chat ID and add one comma then type in your text and tap on send.\nThe message:"+ update.Message.Text);
await bot.MakeRequestAsync(req);
continue;
}
else if (update.Message.Text.Contains(",") && update.Message.Chat.Id == Your_Own_ChatID)
{
string sender_chatID = update.Message.Text.Split(',').First();
string Message = update.Message.Text.Split(',').Last();
var req = new SendMessage(long.Parse(sender_chatID), Message);
await bot.MakeRequestAsync(req);
continue;
}
But if your users send the messages from Facebook to you and you want the bot to send them to your telegram account and answer them again through the bot using Facebook API or something else, all that must change is:
Instead of sender's Chat ID you must save his/her Facebook username and reply it with the FB username instead of telegram Chat ID.
Note that this code is just a sample and of course separating the Chat ID and the reply is a simple solution, but my recommendation is to use inline or custom keyboards to answer the message and that way you don't even need to type down the user's ChatID or FB account.
Also you can use telegram's reply feature and check if the reply is null and find the Chat ID(or FB account or ...) of the sender of the message your trying to reply and send the reply directly to that user.
That is achievable using the method that is used in this project.
[https://github.com/idoco/intergram][1]
Essentially, you create a random userid for each user. In order to reply to that specific user, you have to use the reply to message method in your telegram client. Ie... right click on the message to reply to it.
When I get update from telegram bot with user message written to bot I'd expect to see some id of bot with user id, however, I see such update:
Update{update_id=515450315,
message=Message{message_id=117,
from=User{id=1234567890, first_name='Name', last_name='Surname', username='null'},
date=1470510167,
chat=Chat{id=1234567890, type=Private, first_name='Name', last_name='Surname', username='null', title='null'},
...
As a documentation says User is a sender of a message (user or bot). But in this case user id is actual user id (not bot id) and chat id for some reason equals to user id. So is anybody know how to get bot id during in update object?
This is a JSON object that bot receives telegram when user send a message to bot.( As I understand from your question)
This is completely Normal. You ask why?
For two reasons:
1- When USER send something to bot, at first Telegram servers grab
it and resend it to bot app on its own server. So this JSON object
contains sender (user) id logically.(why?) It is user_id and NOT
bot_id because bot receives message and should know who sent
it.This number(user_id) tell bot about sender.
2- Why chat_id and user_id(sender) are equal? Because when user is
in private messaging with bot ,he/she sends to bot in private chat, so
these two numbers are equal but when user sends something in a group
that your bot is its member also, there are two different numbers:
chat_id that represents group_id here and user_id(sender_id)
that tells to your bot who sent the message.
We can use equality check of these two numbers to find out is user in a private chat with bot or sends in a group.
And I don' see up to know that any JSON objects send from Telegram to Bot contain any field about bot_id. Except some specific methods like getMe method.(it returns basic information about the your bot)