Telegram API: doesn't send message to user until receive first message from that user - python-telegram-bot

I use Telegram API to send a message to a user with my bot.
When the user sends me a message, that operation works but when I want to send a message to an user that haven't sent me any message to me before, then an error occurs (I have his user id):
{"ok":false,"error_code":400,"description":"Error: Bad Request: user not found"}
Is there a solution to solve this?

Telegram bots cannot be a conversation initiators - they can write to user only after that user sends a message to bot first: https://core.telegram.org/bots#4-how-are-bots-different-from-humans
If this error appears in a group, first you need add this bot to that group.

Related

How to let a slack bot send a message as a user to another user?

Consider two users A and B. I'm trying to make a bot that can send a message to user A on behalf of user B, not in the app channel, but in the personal IM channel between A and B. Once the message is sent, it should look like it was sent by user B only. Is there a way to make this happen?
I scoured the documentation, and here's what I tried:
chat.postMessage - This worked well, but the only issue is that when user B tells the bot to send a message to user A, user A gets this message in the app channel, not in the DM of user B.
chat.postMessage with user details - I passed in the username and icon_url of user B in chat.postMessage, so it would look like the user B sent the message. It kind of worked, but not really. User A gets the message in the default 'slackbot' channel. And in the message, although it showed user B's name and image, the "App" tag that's there for bots remained.
So is it actually possible to let a bot send a DM as user B and make it seem exactly like a normal DM to user A by user B? If not, (in the second case I tried) is it at least possible to receive the message in the IM channel between user A and B, rather than slackbot?
The documentation suggested using conversations.open to get the user ID, and then to pass this user ID in chat.postMessage. I tried this as well, but conversations.open gave me an error saying
Error: An API error occurred: user_not_found
The only way to send a message in the DM between User A and User B is to acquire the user token of either User A or B (depending on who you want the message to come from) and use that token to send the message.
It isn't possible to mimic a user and have it appear within the DM between two users.

Bot Framework start a conversation, send a (non reply) message

I am using the Bot Framework Rest API with Node. I am successfully sending reply messages upon a user sending a message (in MS Teams).
I am now trying to start a conversation, to which the response comes back successful, with a conversation id.
( POST /v3/conversations returns me an id - great!)
Then, I try to send a message to that conversation id and I keep getting Service error 'Unknown'. I have tried everything..
Get token function (works fine)
Create a conversation (works fine)
Using the conversationId above, send a message (Not working):
I am following the documentation provided:
https://learn.microsoft.com/en-us/azure/bot-service/rest-api/bot-framework-rest-connector-api-reference?view=azure-bot-service-4.0#create-conversation
Step 1, create a conversation:
Step 2, send message using conversation id from above:
I see nobody is posting so in case someone finds this and wants more detail, here is an on-going conversation about it - https://github.com/microsoft/BotFramework-Services/issues/260

How to get message id of sent message Bot Framework (Teams channel)?

I am using Bot Framework SDK for Javascript. My bot is connected to the Teams channel. Right now I am saving every outgoing and incoming message from my bot to the DB.
But I want also to save reactions of user to my messages. That is why I am using TeamsActivityHandler and onReactionsAdded method (link). In the docs there is written that replyToId field of turnContext is the id of message user is reacting to.
But when I am sending message to the user via turnContext.sendActivity() I don't know the internal id which will be given to this message on Teams side, that is why I can not pair reaction to the message stored in my db.
So my question is, How can I get the id of the message after sending it via turnContext.sendActivity() which will be later send in replyToId field to onReactionsAdded handler?
In other words I want to collect feedback (via reactions) on the messages my bot is sending to the user and save them to my DB (messages and reactions).
Actually it turns out (after some tries) that turnContext.sendActivity() returns ResourceIdentifier which contains one field id and that id is the id which will be given to the message on the Teams side.
EDIT:
For some ResourceIdentifier is empty when message sent to Teams is for example hero card. So this does not completly work.
You can access the activity param after the await command to get this ID. So if we have our response in a variable reply (could be text, hero card etc...) we can get the ID after the await (inside the override async Task OnMessageActivityAsync method)
await turnContext.SendActivityAsync(reply, cancellationToken);
string responseMsgId = reply.Id;

How to get a welcome message on teams even before user sends any message

I have deployed my bot on teams channel.
I would like to send a welcome message to a new user even before user sends a message to the bot.
can we achieve this for teams channel?
If yes, which event can be used to get that user is accessing bot for the first time.
You can use the ConversationUpdate event ActivityTypes.ConversationUpdate // in c#
When a bot is installed, your bot receives a conversationUpdate event. You can then send a proactive message to the user. Could you please try sending a proactive message and let us know if you face any issues?
The conversationUpdate event with the membersAdded object in the payload is sent when either a bot is added to a team or a new user is added to a team where a bot has been added. It is always a good practice to send a welcome message introducing the bot to all the users. Ensure that your bot responds to the conversationUpdate message, with the teamsAddMembers eventType in the channelData object. Also, keep in mind that the memberAdded ID is the bot's App ID itself, because the same event is sent when a user is added to a team.
Hope this helps.

Can't send message to some bot users in Telegram

I made the bot in telegram which accepts some requests from users. My bot should send notifications about changes of the request status. I do it separate from my script by sending get request. But some users can not get the notification message, because this error "{
"ok": false,
"error_code": 403,
"description": "Forbidden: bot was blocked by the user"
}" The user didn't block the bot. The bot blocked itself for some reason. I can't understand how it happens. What is the reason of blocking bot by the user unconsciously? I want write the guid for user "how do not block bot", but I don't know the reason. How I can solve this issue?
Here's my request:
https://api.telegram.org/bot<bot_token>/sendMessage?chat_id=<chat_id>&text=<Your request status changed>&reply_markup={"inline_keyboard": [[{"text": "View", "callback_data": "<request_id>"}]]}
Your bot is blocked by users yet, need to click RESTART to unblock bot.
You can try it yourself by click Stop Bot in menu.
I had the same problem, revoking bot's token solved it.

Resources