ways to get chat id of a phone number in telegram bot - telegram

I want to know what are the ways to get the chat id of phone numbers in telegram bot programming. I have a small project that I need to get Chatid of a group of phone numbers in telegram very fast .

Telegram's API for now only allows bots interact with people using their ChatId.
Short Answer: There is no way provided by the API to achieve what you want.
Long Answer: You can manually add this number to your contact list and then send them a message with the link to your bot (for sure you need to send them something promising or else they will not open your bot). Once they click /start creating a function that stores the chat_id + firstname in a db so you can easily retrieve later then your bot can ask for the contact of the user so you can know which chat_id belongs to a particular phone number (if the user shares it with you then fine else at least you have the chat id which is important).

Sorry, you can't. Telegram bot API work in next scenario: User interact with Bot first and bot may ask for a message or for phone or for location. There is no way to send phone number and get chatId. You can ask user for a phone and in the response, you will give chat ID and Phone number of user if user will send phone number to the bot.
After it, you can campare revieved User's phone number with your database of phone number and append it with chatId.
Hope it help you.

Related

Retrieve customer email from phone number via WooCommerce REST API

To integrate a VoIP system to our email client, I need to retrieve the email address of a customer based on the phone number used for the call.
I tried many requests to the WC API but none worked.
I know the phone number is stored in the "Billing properties" of the customer but I cannot find a way to make it work.
I believe (if is it possible) that a request close to this one should do the trick:
https://www.website.com/wp-json/wc/v3/customers?filter[phone]=123456789
Thanks to anyone that could point me in the right direction.

Telegram BOT - How to get chat ID of users in my group?

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

how to read/receive telegram channel messages in my telegram bot?

i'm trying to create a bot which can read/receive all messages in a specific channel and send them to me .
my problem here is that i can't find a way to access those messages in my bot
important thing is:
i'm not admin or creator of that channel
i don't want to ask the creator to add my bot as administrator
i've searched in google but i wasn't able to find a solution
and i'm also sure that it is possible to do it, because there are already some junction bots with exact same performance .
any references or suggestions are appreciated .
As already pointed out in the Telegram group of python-telegram-bot, bots can't receive messages from channels where they are not an admin. If you want something like this, you'll have to use a user bot, e.g. a program that controls your private Telegram account (in contrast to controlling a bot account). See here for some info on user bots.
Note that also the provider that you linked seems to be using userbots behind the scenes. More precisely, the docs on the so called "DirectConnection" state that you need to enter a phone number (associated to a telegram account) and then "Follow the instructions" which probably just means to enter the verification code that Telegram sends you. Phone number + verification code is exactly what is needed to control your private Telegram account.
Disclaimer: I'm currently the maintainer of python-telegram-bot.

ignore positive chat I'd telegram bot

I have webhook a telegram bot for search data my a hosted
How can ignore positive chat I'd by bot I have a bot to search files from my hosted data And get link using telegram I want that bot just work in groups only If any person try to use it in personal chat it will not give reply means not search data and not give a link
Every message has a chat field and each chat has a type see telegram bot api
Type of chat, can be either “private”, “group”, “supergroup” or
“channel”
check if type of chat of message is equal to “group” or “supergroup” then do what you want.
In php can check like below
if($message->chat->type == "group")
...
Can you clear before using this command
if($message->chat->type == "group")
Need other commands in header
Or full command please

One bot managing many discussions with one user

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.

Resources