How to send message to the user by using telegram id and python_telegram_bot library? - telegram-bot

I want to send the message to anybody by using his telegramid and python_telegram_bot library.
I can send the message to me by using below code but if I put other's id then I can not send the message and it says chat not found message.
updater = Updater(mybot_token, use_context=True)
updater.bot.send_message(chat_id = receiver_id, text="welcome")
I am not sure why it is only possible to send the message to me, not the others even though I puth the chat_id as their telegram_id.

Bots can only send messages to users that have already started the bot. See the Telegram Bot docs.

Related

Messages sent to my sample Telegram Bot cannot be seen by one with whom I share the bot link

I have created a sample Telegram Bot. http://t.me/zOS_Telegram_bot
I am being able to send text messages to the bot. For example, check the "Testing our new Telegram Bot!!!" messages that I am being able to send to the bot. enter image description here
However, when I share the bot link http://t.me/zOS_Telegram_bot with someone else, he/she cannot see the messages. What is it that I am missing here?

Get chat_id from bot to bot conversation

So What Im trying to accomplish is a bot that forwards messages from one specific user to one specific group chat. I started my testing by using my own chat_id and the bot perfectly forwards my messages to the right groupchat.
The problem is tho, that I want to forward messages that I receive from a bot. So I am trying to gather the chat_id between this bot and my bot but I can't get my head around how I should send and/or receive a message from this bot to gather said chat_id because I cant use it's #username in a /sendMessage? URL.
Why doesn't my bot see messages from other bots? Bots talking to each
other could potentially get stuck in unwelcome loops. To avoid this,
we decided that bots will not be able to see messages from other bots
regardless of mode.
Telegram Bots FAQ

How to receive messages in group chats using telegram bot api

My telegram bot receives messages sent by user to my bot in private chats but not receives messages sent by users in group chats. Any options/api for getting group chat messages also,.
Talk to #botfather and disable the privacy mode.
Sequence within a BotFather chat:
You: /setprivacy
BotFather: Choose a bot to change group messages settings.
You: #your_name_bot
BotFather: 'Enable' - your bot will only receive messages that either start with the '/' symbol or mention the bot by username.
'Disable' - your bot will receive all messages that people send to groups.
Current status is: ENABLED
You: Disable
BotFather: Success! The new status is: DISABLED. /help
By default A Bot will receive only messages addressed to it by any user directly via posting by /command#YourBot any message you send.
After that it vill be available via getUpdates API call.
In browser it will be:
https://api.telegram.org/botToken/getupdates
Find the related message in output JSON and grab chatId. It will allow you to answer back with:
https://api.telegram.org/botToken/sendmessage?chat_id=123456788&text=My Answer
Make your bot by admin in group.
You can access all avaliable settings from all of your bots by sending /mybots to Botfather. Choose the bot, then Bot Settings and Group Privacy. If its disable (default), you can tap on Turn off.
Now its possible to receive the chat history using GetUpdates. This can be done via HTTP API or the frameworks. For example, in C# (.NET Core) like this:
var bot = new TelegramBotClient(ApiToken);
var updates = bot.GetUpdatesAsync().Result;
foreach(var update in updates) {
Console.WriteLine($"{update.ChannelPost.Date} {update.ChannelPost.Text}");
}
But keep in mind that this feature has some kind of perfect forward secrecy implemented. So you only get messages that were send after group privacy is disabled. As a result, the GetUpdates result is empty until some post was made.
if you added your bot before disable the privacy mode, you should remove the bot from the group and add it again

can Telegram Bot sends message to group?

I create a group on Telegram and created a bot and add in.
I am trying to send a message to group that I created and the error shown as below
{"ok":false,"error_code":403,"description":"[Error]: Forbidden: can't write to chat with deleted user"}
I have use getUpdates from Bot Documents and managed to get chat id and doesn't work again for me. p2p (private type message) works for me but not group type.
Any advice please? Thank you.
Yes you can, you have to invite the bot into the group, grab the chat_id of the group and send the message as you are sending a normal message to a private user.
The error message is self-explanatory tough.

How can I send message to specific chatID?

I have chatId and want send messages while execute some tasks from java code. I found this explain on telegram "Bots can't initiate conversations with users. A user must either add them to a group or send them a message first. People can use telegram.me/ links or username search to find your bot." But my task works good when I use https request directly from browser. My bot perfectly answer for requests but how I can do this without user request?
I can not truly understand your case!
Anyway, your bot can send a message to a chat ID Only if the user witch blongs to the specified chat ID added your bot (send start to a bot).
and if it happened then send your message with
/sendMessage