I've created new bot for Telegram. I've set /setinline in BotFather for my bot. I've added a webhook that is called when I send a message to bot but this webhook is not called if I write something in the bot chat without send any message.
Any idea how to solve?
Yes, it does, probably you're inspecting the wrong param, it will call the same webhook, first remember you set the webhook by doing:
https://api.telegram.org/bot<BOT_TOKEN>/setWebhook?url=<YOUR_URL>
and like you mentioned, you need to enable /setinline through BotFather, then it will call your endpoint with a message with the following body:
{
"query":"tex",
"from": {
"username":"user",
"first_name":"firstname",
"last_name":"lastname",
"id": 8888888,
"language_code":"en-US"},
"id":"7777777",
"offset":""
}
Remember it will call your endpoint on key-up you may receive a ton of request.
Related
There's a thread that my webhook has previously created that it wants to reply to. Is this possible using a webhook? It seems to be possible with a bot, see this answer:
https://stackoverflow.com/a/58657945/3832377
But I can't find any documentation on doing it from a webhook. As I've created the original message in the thread, I can guarentee a consistent threadId.
I tried to send a body that looked like:
{
"cards": [/* a card */]
"thread": { "name": "some_thread_name" }
}
But received a 500 error.
Documentation: https://developers.google.com/hangouts/chat/reference/rest/v1/spaces.messages/create
States you have to add the threadKey as a query parameter, not in the request body.
I'm trying to set my bot's typing status by sending the following POST request (based on the API docs):
https://api.telegram.org/bot{{botToken}}/setTyping
{
peer: {{chat_id}},
typing: true,
action: 'sendMessageTypingAction'
}
I've tried a few variations of it, such as changing the url to be /messages.setTyping and sending the action as {"_":"sendMessageTypingAction"} as seen here, but all I get is:
{
"ok": false,
"error_code": 404,
"description": "Not Found: method not found"
}
Anyone know what I'm doing wrong?
Thanks to #tashakori for pointing me in the right direction towards the Bot API. For posterity, what I needed to do was:
https://api.telegram.org/bot{{botToken}}/sendChatAction
{
chat_id: {{chatId}},
action: 'typing'
}
The link you have mentioned above belongs to Telegram Core APIs which is used for handling ordinary accounts of Telegram. These so-called Core APIs are not related to Telegram Bot APIs.
The only API that is somehow similar to SetTyping for bots is AnswerCallbackQuery, which can be used only when responding to the user's interaction with inline keyboards. (you can send a text to the user, saying that there is a process running in the background and whenever the user's answer is ready, you can send it using APIs like sendMessage)
So I have created Messenger bot. Is there a way to receive webhook when someone who was interacting with bot has blocked it? Similar to how you can set up webhook when someone uninstalls facebook app.
When a user first interacts with the bot I store his information in the database. If he decides to block the bot, I want to delete that row from the database so receiving messenger_id would be completely enough.
I read through FB docs but did not find anything useful. Would appreciate if someone could help.
You will receive an error code when you try to message the user from your bot. Probably something similar to this:
{
"error": {
"message": "This Person Cannot Receive Messages: This person isn't receiving messages from you right now.",
"type": "OAuthException",
"code": 10,
"error_subcode": 2018108,
"fbtrace_id": "BLBz/WZt8dN"
}
}
Try going through your response logs finding that user PSID to see the exact error you are getting, but it should be very similar to the above.
So what you have to do is update the user when you get a response like this consistently, perhaps set a counter or build a rule for when you decide is enough to remove the user form your DB or disable. More info on the errors here:
https://developers.facebook.com/docs/messenger-platform/reference/send-api/error-codes
I know I create new bot, give it name, description from BotFather inside telegram
But this only adds the bot, when I modify my bot, code some functionality in python\lua\php etc - where should the code go and how telegram will know the behavior of my bot?
Who runs the new code, where should I upload my new additional code for my bot?
Does it go to telegram server and runs there on the cloud?
If so, how to upload it?
After you have setup your Bot's identity (#bot_name) with BotFather, the next step is to design the interaction/functions your Bot will perform.
Your bot code lives on YOUR server.
Requests from users interacting with your #bot_name will be routed from Telegram to your servers which ...
1) you have setup with a webHook (using the setWebhook method) so Telegram knows where to send your bot's requests
or
2) your bot polls Telegram's Bot-API repeatedly asking if there are any new updates (i.e. messages users sent to your bot) using the getUpdates method
Your bot receives these messages, and replies as directed by your bots "code or logic"
hope this helps.
You can run the code quite easily from your machine.
For example how I did it using NodeJS:
1)Install NodeJS on your machine (details - https://nodejs.org/en/download/package-manager/)
2)Install Node Telegram Bot API (https://github.com/yagop/node-telegram-bot-api)
3) create a file like this, filling in with necessary changes:
const TelegramBot = require('node-telegram-bot-api');
// replace the value below with the Telegram token you receive from #BotFather
const token = 'YOUR_TELEGRAM_BOT_TOKEN';
// Create a bot that uses 'polling' to fetch new updates
const bot = new TelegramBot(token, {polling: true});
// Matches "/echo [whatever]"
bot.onText(/\/echo (.+)/, (msg, match) => {
// 'msg' is the received Message from Telegram
// 'match' is the result of executing the regexp above on the text content
// of the message
const chatId = msg.chat.id;
const resp = match[1]; // the captured "whatever"
// send back the matched "whatever" to the chat
bot.sendMessage(chatId, resp);
});
// Listen for any kind of message. There are different kinds of
// messages.
bot.on('message', (msg) => {
const chatId = msg.chat.id;
// send a message to the chat acknowledging receipt of their message
bot.sendMessage(chatId, 'Received your message');
});
4) Finally launch your command console (like cmd on Windows) navigate to telegram bot directory where the script is located and type node index.js (assuming your file with the bot script like above is named index.js)
Following these steps you will have a fully functioning bot. As you make changes to index.js you can simply rerun the command "node index.js" in console.
The procedure is similar if you need to set up a bot on a server.
Hope this helps.
I'm successfully using Bluemix Push to send notifications via the REST interface to an iOS app with a simple string alert message. That works fine.
Now I would like to send a more complex message where alert is a dictionary and has a sibling "category" element per The Remote Notification Payload.
Is this possible with Bluemix Push? Whenever I try to deviate from the basic structure, I get "Bad Request - Invalid JSON".
After much head-scratching, I finally picked up a hint from https://www.ng.bluemix.net/docs/services/mobilepush/t_advanced_notifications.html#t_push_badge_sound_payload and figured out that since the category field is unique to APNS, what I needed to send is
"settings" : {
"apns" : {
"category" : "myCategory"
}
#DSchultz_mo I was having issues to find the documentation but I finally found it, so if you go to https://mobile.ng.bluemix.net/imfpushrestapidocs/#/ you can use swagger to register your device and send notification and the magic button is in model there is more details for sendMessageBody