Telegram Bot webhook really slow - bots

I've created a telegram bot and set a webhook as described in the docs. For testing purposes I've set it up so once you send the bot a message it replies back with the same message.
Now the issue I am having is that the updates from telegram are coming back really slowly and there are some messages I haven't received yet. Am I missing something or is the webhook method just really slow?

I had the same problem. Turns out I wasn't responding the telegram server after I got the POST request. Due to this, the server wasn't sure if I got the previous updates and was constantly sending my webhook past updates.
I have an express server and I added this bit of line after handling the POST Request.
res.sendStatus(403)
You can also confirm this by going to this url
https://api.telegram.org/<token>/getWebhookInfo
You'll see a property called pending_update_count. It should zero or close to it.

Related

How to use the Discord JS Client without logging in?

I have a service that listens for certain updates and then uses a Discord Bot to post a message on a channel. A random example: every time a team scores a goal, post a message in a channel. I got an email from Discord to reset my bot token because there were too many logins.
As you know, in order to use the Bot you use the client.login("XXX") method. So every time there is an update my service initializes the bot and then sends a message. My assumption is that it has to do with me calling client.login("XXX") for every update. Since my service runs serverless, I can not keep the service up.
Is there a way to make the bot post a message without having to use client.login("XXX")? Or can anyone suggest any strategy to make this logic work?
That is not possible as a bot cannot do any actions without being logged in, it sounds like channel webhooks would fit your needs better.
You simply generate a webhook link in a channel which you can then post messages to through a post request.
You can read more about webhooks here
And you can read more about the required paramters and how to format a POST request to the webhook here

Discord bot that sends messages recieved from webhook

I am trying to make something that will send a notification to my phone via discord when a webhook is called. The notification should have a body of text, and could be something like a python error, or just some plain simple text like "hi there".
I built a discord bot that uses an overridden python BaseHTTPRequestHandler, running in its own thread, which sends the server messages via client.loop.create_task(self.get_channel_by_name(name).send(message)). However, it is pretty slow (takes a few seconds to half a minute to go from webhook to server message, when it really should be almost instantaneous)
I'm thinking I have taken the wrong roundabout method for building my webhook discord server, but I have no idea the right way to go about this, and though I would ask the community. Any thoughts on how to go from requesting a specific file like "http://localhost:8000/post/category/channel/encoded-message", to the specified message in my discord server in a specific channel in a given category? Thanks for any advice!
I figured it out after a bit of googling. Here[https://discord.com/developers/docs/resources/webhook#webhook-object-webhook-types] is the discord api for creating bots using webhooks. The trick is you go to the channel of the server you want to send messages to, and in the settings, add a webhook in the intergration tab. No need to mess around with the discord python package. I managed to start sending messages using python requests library, and nothing else.
import requests
requests.post(f'https://discord.com/api/webhooks/{webhook.id}/{webhook.token}', data={'content':message})

i cant visit the message that i sent with getupdates in telegram bot

I can't visit the message that I sent with getupdates in telegram bot
https://api.telegram.org/bot............./getupdates
how can I visit the messages that I sent with my telegram bot?
I want to show the messages that send with a bot with sendmessage method but I couldn't find it
I can find my the message_id between sent messages but I can't visit the message that bot sent
From your question I couldn't extract in which language you are coding your telegram bot.
In node.js for example, using this package, every message you sent is automatically written to the console. If you only want to review your message that should already do the trick. If you need to store it permanently you'd need to either try to find where the console.log happens and apply your own code or save the console output to a file (like mentioned here). Later on you could for example apply a regex to filter the needed messages.
Note: If you are not using any programming language yet (and are just sending to the telegram API URLs) you have no easy possibility of reviewing your sent messages apart from intercepting the HTTP packets.

Cannot set the webhook of my Telegram Bot

I set the webhook of my Telegram Bot and it seems to work fine, but the bot doesn't reply when I try to write him. The code of the file I indicated as webhook is correct (I checked it with getupdates method) and the server where it's hosted has the SSL certificate.
Trying to see the result of the method getWebhookInfo I checked up that the error was "Wrong response from the webhook: 410 Gone".
Anyone could help me to find out where the problem is?
I recommend you to copy the url you received from getWebhookInfo and then POST some valid JSON to it (e.g. on linux with curl, examples here: Telegram Guide).
WRON RESPONSE FROM WEBHOOK indicates that there is a problem with your web server configuration or something elso on the way in.
"410 Gone" is returned by your webserver, so maybe your .httaccess config is wrong (if using Apachee).

How to detect bot message/user message?

My FB-NodeJS-API prototype is not working correctly because my webhook is receiving the bot respond which is then sent to API.AI.
I need to set a condition where only a user's message should be received on the webhook request or only user's message should be sent to API.AI.
Can anyone advise me on this?
Can you explain the problem better? Please add the relevant code.
The bot response should go the user, not the webhook. The user input will come to the webhook.
I would suggest getting the bot to work without API.AI first and then adding support. My bot is in node.js so you may just want to jump to the source code.
For more information on setting up a bot see my article Facebook Bots for Fun and Profit
The example bot is DMS Software Bot
The source code is Github fb-robot

Resources