To attract members of the channel specified in Telegram and send messages - python

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.

Related

Using Discord's API to Register New Messages

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 to get the last message of a specific user in a specific channel in Slack?

I know how to send messages to a channel by using chat_postMessage. Is there a method that retrieves messages from a user in a specfic channel?
You could do this retroactively by using 'conversations.history' and filtering through the messages by user id. You can also do this proactively by using the Events API and subscribing to the [message][2] event type. Again you'd have to parse through the event response to get the channel and ser specifics.

Is it possible to harvest messages from other peoples discord servers?

Can I use the discord API in python to harvest messages from a server (not my own server)? Assuming you have an invite link.
Thanks
Yes, it would be possible. If you look under the TextChannel section of the Discord Models section of the discord.py API Reference, there is the TextChannel history() method. This can be used to parse all the messages in a channel. If the limit argument of the method is set to None, then all the messages in the channel will be returned.
Since you say that the bot already has an invite, that implies they have access to a good part of the server. The method I mentioned requires the following permissions for your bot:
See Text Channels
Read Message History
Well, if your using a discord bot, you need them to invite your bot to their server.
Other than that you could theoretically listen with a bot on your own account but that would be against the discord TOS.
You can achieve this through a discord bot. Given that bots respond to events that fire within servers they reside in, you can listen in to incoming messages.
An example of such event can be found in discord-py documentation.

Delete messages sent by telegram bot

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).

Receive message from slack bot

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.

Categories