i have a telegram -bot in a group which sends messages like current weather, stock prices , news and so on. at the end of the day i want to clean up the messages sent by bot. however i unable to get the message id of the messages sent by bot using the api 'https://api.telegram.org/botxxxx:xxxxxxxxxxx/getUpdates' and hence i am unable to delete message created by bot. any updates on this issue will be appreciated
you should store the message IDs when invoking the send method (from the message object returned) and delete those messages while emptying out your message id storage later on.
This is efficient than your approach for couple of reasons. For instance, with your approach you may have to filter out other messages/updates on that channel that weren't send by the bot (if your bot isn't the only admin who posts content).
Related
What I'm trying to understand is how Discord.py creates and sends responses from their on_message function.
Take this as an example:
#client.event()
async def on_message(message):
print(message.content)
I'm trying to understand how Discord.py retrieves new messages from Discord without refreshing the channel histories for every single channel in every single server to scan for new messages which would surely hit Discord's rate limit.
Is there a way to scan for new messages with Discord's API using fetch or post requests? I am not trying get a solution on how to scan new messages using an already made library. I want to achieve this using only the requests module in python.
I'm trying to understand how Discord.py retrieves new messages from Discord without refreshing the channel histories for every single channel in every single server to scan for new messages which would surely hit Discord's rate limit.
Discord bots establish a websocket connection with Discord's servers, which is essentially a (secure) two-way tunnel. This means that once the connection is up, Discord can send events to you. Instead of you having to manually fetch every single channel, Discord tells you "Hey, a message was created", and the payload attached will give all the additional info about it.
The Discord (not discord.py) docs have detailed info about how everything works behind the scenes, to help the people creating the Bot libraries for you. For example, this section details which types of events Discord can send to you. To see how something is constructed, click on one of the event types and read up on the data that Discord provides.
Is there a way to scan for new messages with Discord's API using fetch or post requests? I am not trying get a solution on how to scan new messages using an already made library. I want to achieve this using only the requests module in python.
Not really, unless you do in fact send a GET for every single channel, which will get you ratelimited. There's really no reason to ever use only GET/POST requests (other than Webhooks, where you just send a POST with your info to send a message to a channel without a bot).
If you'd like to read up on Discord's API, the docs I linked contain a full spec of everything, so you could try to do whatever your heart desires (... and the API supports).
how can I attract members of a group or channel in telegram using python and send them a specified message? I couldn't find any resources on this subject, can it be done with pyrogram or telethon?
If you mean send them messages privately from a bot, you can't do that.
Telegram doesn't allow that.
User has to reach us to the bot in order for the bot to send messages.
Although you want to send messages to your bot users, you can use pymongo or any other database and store user info (id, name etc). Then by accessing and iterating through the IDs you can send messages.
And you mean sending them messages within the group, you can just create a update filter and add reply to it.
Don't think there's any way of doing this in a channel.
I'm trying to get the slack UserId of the user who initiated a conversation with a bot.
I tried using users.identity scope and api, but I'm only getting the UserId of the user who created the bot. The bot will be used by multiple users so I want to have an isolated chat for each user by getting the exact UserId of the user who is currently having a conversation with the bot.
I'm using Python, Amazon Lex and Slack.
Can somebody point me to the right path?
If the conversation is initiated as a direct message with the bot, you can subscribe to message.im event. You'll receive this event every time a user sends a message to the bot. In the response JSON body, event.user should provide you the userId.
It could be a different solution depending upon how you are making the app, and where do you need this information.
I want to fetch all the messages sent by my bot in Discord.py .. I've tried a lot but I only found ways to do that for the last message.
Is it a function available in Discord.py?
There is no internally-kept list with information about the messages sent by your bot -- as such, you have two methods to find all the messages sent by it:
Create your own system to track and save messages or message IDs that are sent out, or
Iterate through the history of the guilds' channels that your bot posts in. Note that if any of these channels have a long history, iterating through all of it could be extraordinarily slow, especially if you have a public bot in multiple servers. If you choose to do this way, you can use the TextChannel.history method.
I am quite confused on Slack bot using Python. I want to be able to receive messages sent to by bot:
client = SlackClient(API_TOKEN)
if client.rtm_connect():
while True:
print client.rtm_read()
time.sleep(1)
else:
print "Connection Failed, invalid token?"
Then I send a message to my bot in slack. But I don't get the message. How do I start sending message to my user?
Also, is it possible to include the bot in all channels? So if I'm in any channel, I want to be able to say #myBot args 123
Slack only sends events to bots who are joined to a channel and by default they are not joined to any channels and receive events only for private messages. If you invite your bot to the channel then Slack should start routing events from the channel to it.
As for the second part of your question, mentions (e.g., #bot) are not special events and you must check each incoming event to see if it is message that is directed at your bot (see this answer. One gotcha is you need to know the ID of your bot as the event will contain something like <#YOURBOTID> args 123. Finding the ID of your bot and other useful tips for building a python slack bot can be found in this article.
There are many types of events in slack, if they have been subscribed by your BOT, then your BOT will definitely get related traffic on your request URL.
So, if you want to receive any message that has been directly sent to your BOT, you have to subscribe direct message event.
And if you want your BOT triggered by #bot .. kind of messages, then you need to subscribe app_mention event. Your BOT would receive traffic if it has been mentioned in any group but it can post a message to the only group in which it is allowed to.