how i made a ridiculously simple but fun bot — with fbchat

Devops at Leapfrog Technology Inc.
Search for a command to run...

Devops at Leapfrog Technology Inc.
oho
Do you understand the difference between "looks good" and "is good?"

For more than 3 years I've been doing DevOps and involved myself in multiple projects ranging from simple static web applications deployed to some CDNs to multi-tenant systems with event-driven architectures. I've always found some ways to make my bo...
One of the problems that I face frequently when writing Infrastructure as a Code is how you structure it. To answer this question, I think there are a few indicators that decide how we want to structure. One resource will have less change compared t...

This may come as a surprise to you. How can someone use nginx configuration with Javascript? Fortunately, nginx supports a language called njs which is a strict subset of ECMA5. This can be used to further extend your routing logic, but don't be that...

This is my first blog of multiple blogs on developing a pod troubleshooter turned into a compiler as a service. What do you call it CaaS? COMPaaS is cooler though, lol. I've been learning a lot of things in this journey, so I decided to share about i...

Hello hahaha.
It’s ridiculous I am writing a article about a very simple bot which just texts randomly yet so many people chatted with it and didn’t notice hahaha. Though, some people got triggered but who cares xd. Pornhub wouldn’t exist if he asked about his startup idea with his family, right? hahaha.
So, I talk with a lot of girls ( i mean, ofc ) and when i get bored all i text is hora and haina hola all the time. I wrote a pyautogui program which captures new text and types eh ok aru vana long ago. hahaha that was also so fun. i triggered many garals.
The idea was relatively simple I would capture the chatting person’s profile picture and check if new instance exists (because facebook renders avatar next to text) for every new message. the code was something like this….

But this was very simple and checking image was too redundant and boring. As I needed to register every new photos and my code broke when they change profile picture. So, I checked facebook docs to see if they offer any messaging api.
They did offer one but it was nodejs sdk. And I do javascript but ( i dont enjoy it) idc what you say. I just don’t enjoy writing cli scripts in nodejs. I prefer python.
So, I found this amazing module called fbchat hahaha with best docs for a personal project out there. ( Link in bottom )
I wrote a simple bot which just replied with hora and haina hola randomly.

Something like this and running it was so easy just pass and initialize your client and write some codes to secure your email and password as you dont wanna expose it on your github hahaha.
Then, I made a wordlist of like 200 words and it sent randomly from that list hahaha.
Let me add some screenshots.



hahahaha.
Then people said i should add some commands to this.
Then i first added -s- to start the bot and -x- to stop the bot. The mechanism now was. I would record the thread id and if it’s one of those command it would save / remove their id from thread id list and the bot will reply only to those who have their names on thread list something like this…

Pretty straight forward right hahaha. And my send texts code was just checking if incoming message belonged to my list.
Then, I took it one step further.
Now the bot sends kanda ( porn for nepali) hahaha. The mechanism is it justs forwards a kanda video from one kanda group. I ditched this later as i dont wanna get in any legal troubles.
I added meme, when the message is -meme it will scrap reddit and send you a mem.
I added joke, also when message is -joke it sends you a random joke from one random api i found on the internet.
I also added voice message if you message something like -say {hello} it will say hello in voice message using google tts.
So the code was like this now..

The code is dead simple in like 100/150 lines but it was so fun.
Github: https://github.com/geekyarthurs/chat-bot
Docs of fbchat: https://fbchat.readthedocs.io/en/stable/api.html