Bot gets and replies to a mention on twitter problem - python

I'm trying to create a Twitter bot with Python. So my problem is, is there a function that allows me to get the mentions of a tweet, so I can reply to them?

To write a bot who can reply to tweets mentionning it :
You can use the standard statuses/filter API to watch for tweets mentionning your bot.
For this, the standard search operators says that you just have to write "#yourbot" in the query to get tweets mentionning this user.
Then you can use the POST statuses/update to reply, with the in_reply_to_status_id parameter which is the tweet id to reply to.

Related

Access info of tweet above mention using Tweepy

I am making a Twitter bot that transcribes video to text, when people mention the bot on a tweet, I want to get the information of the tweet they mentioned me in, could that be possible with Tweepy?
Sure, you can use Tweepy for tweet statuses.
Here is the link for it:
https://docs.tweepy.org/en/latest/api.html#tweets

How can i search for a specific message in a chat in python? (pyTelegramBotAPI)

I'm programming a Telegram bot. I want to search for a specific message in a telegram channel and get its message id. Is it possible? Thx in advance.
As far as I know, you aren't able to search though messages (in a specific chat) by just using Telegram's bot API. You need an MTProto client to do that. You can use pyrogram or telethon to interface with MTProto then use messages.search.
But, there is a catch. If the message you're searching is in a channel, you can webscrape https://t.me/s/CHANNELUSERNAME with a library like BeautifulSoup.

Send a message to all users when the bot wake up

I've started tinkering with python recently and I'm on my way to create my very first telegram bot mainly for managing my Raspberry Pi and a few things connected to it. The bot is done but I would like to send a message to all the users that have already interacted with the bot when it starts, basically saying something like "I'm ready!", but I haven't been able to find any information about it.
Is there any specific method in the API already done to do this? Or should I create another file to store the chat_id from all the users and read it with python?
Thank you all for your help!! Regards!
You should have a Database that stores Chat-id(s) of Clients that interact with your bot.
If you're able to put them into a list, then the job is half done.
All you need to do is to create a "for loop", and send message to all the ID(s) in the list.
Example:
message = "Good morning"
chats =[1234447488,3748838477,4748848578,7463638488]
for chat in chats:
bot.send_message(chat_id=chat,text= "message")
In case of of clients that have deleted your bot, you may experience an error. You can catch that with try and except.
Is there any specific method in the API already done to do this?
No, there's no such method.
Or should I create another file to store the chat_id from all the users and read it with python?
Yes, you should handle it yourself. Usually user ids and another information about User <-> Bot interaction is stored in a database on a server, because it's easier for maintaining and searching.
So if you want to send a plain text message to your users in a file, you should call SendMessage method of telegram bot API for every user in your file.
You should save users in database or file.After that use for to send_message one by one to all users that you have in database or file.
Yes you should create another file or use a database to store the chat_id of all the users you interact with. You can check Telegram Bots API to see all the available commands. if there is no such command then there probably won't be any command in the wrapper you are using for python either.

Twython - get tweets only from one user, not to that user

Fairly new to Twython, hope I'm not sounding too dumb here.
Currently I have Twython listening to the Twitter streaming API for tweets from a single user, then triggering a relay to open a door. It's working well, but I've found that it will trigger whenever my target user tweets something (good) AND whenever anyone tweets anything to my target user (not good).
Is there any way to have Twython trigger an action only when a user tweets, and ignore any replies or new tweets that user?
Any help much appreciated - thanks for reading!~
you can check the tweet's user field (in the json you get from your stream listener) and verify that it was tweeted by the desired user.
look here for further details: https://dev.twitter.com/overview/api/users

How to use Twitter Streaming API?

I been successfully able to use Twitter REST API to do find tweets and retweet them automatically. Now I want to tweet user a Thank You Message, I am using Python and Tweepy for my BOT. I can do live collection of tweets, using Twitter Streaming API, but I can't understand how to use the API to send a thank you message to those who favorite my tweets. I saw both the documentations but couldn't understand and use much from there. I also tried to search for any example but couldn't find any good one for Streaming API.
Can anyone show me how to use it with tweepy to achieve the same. It would be nice if you can show how to use it when someone retweets my tweet or follows me, I want to send them a thank you tweet automatically.
PS: I understand that Twitter doesn't likes much automation. But its all for learning.

Categories

Resources