My friends and I swear to help other people

I said in my previous post that one of the rules of the one week challenge was that I should get in deep about a subject that I learned/worked on during a given week.

I should have probably stated what my goals (rather than just the rules) are with this challenge, but I didn't, whatever, now it's too late. I'm writing about Telegram bots because I decided to replicate what I read somewhere a while ago. Someone said that they were building an bot that would help them not to swear so much, mainly in work chats. Why not build a Telegram bot about it?

When I'm writing in english I swear as fuck, but I don't in Portuguese, it probably has to do with the education I received. Almost everyone else I know swear, one friend of my, specifically, swears a lot… more than you just thought. So I said fuck that I'm going to make these motherfuckers stop swearing.

I bet you can't read it. Your problem, go find a way.

The idea

Build a Telegram bot that keeps track on how much each individual of a group swears. The group can start voting to add or remove bad language. Every time someone say one of those words they own more $0.5. At the end of a period the bot says how much each one has to pay. Pay to who? That's the group's choice, the bot will suggest some charity (yeah, I'm the Bill Gates of my generation).

Don't be an asshole

The plan

These are the steps to follow in order to build this/a Telegram bot:

  • Talk to the FatherBot (awesome name, isn't it?)
  • Build the actual bot
  • Setup a server
  • Run the bot
  • Swear a fuckton
  • Charity profit

Let's work from build the bot to run it, I believe you can do the rest by yourself. Oh… I forgot for one second that nobody ever reads this…

Build the bot

That's my friends and I, ready to build the bot

The easiest way to build talk with Telegram is to use something called Webhook, I'm a mobile guy so I never heard of it. Weebhook is basically a callback. Follow me: Telegram wants to talk to the bot, right? It would be nice to have one place to handle every request to the bot, right? Would be a win-win if Telegram could keep an URL where they can send all new events and you could respond to those events, right? You can see where this is going… That's exactly what Webhook is, I say: Here it's Telegram, this is where you can find me and Telegram will call me every time that it finds something that might be interesting to me.

Telegram is awesome, it really is. They wouldn't use an insecure HTTP to talk to the bot, right? Yes, you are right, Lorenzo. All requests will be made only through an HTTPS connection! Nice. So I also need to generate private and public keys and send them to Telegram…

PS: Do not forget that Webhooks only supports ports 443, 80, 88, 8443.

STOP! There's one problem. I'm not a web guy, I'm starting to learn Node.js, I don't want to spend 2 months to learn everything before having this bot up and running. Fuck that, I'll start to write some code. How can I do that?

I met an awesome guy a few years ago his name is Yago, just kidding, he has an awesome repo on Github, It's called node-telegram-bot. Can you guess what it is about?

Easy interface with Telegram Bot API > check.

But I still need to have to generate keys and set up a server and blah blah blah… nope, Yago got you covered. Look at this example. That's the whole bot, I mean it. I can go ahead, create an account on OpenShift, learn how to upload a node.js project and boom, it's working. Amazing huh?

The actual "Ele xingou" ("He swore" in English) bot is still a work in progress. The first version will work only with Portuguese bad language, but they say that GitHub has something to do with open-source, I don't know, maybe someone can help me. (You probably already realize that my English is… awful).

Setup a server

If I wanted to get shit done I would go to openshift.com and work from there, otherwise I'm completely lost. I am not a web developer.

Why did I even made this a separated section?

Run the bot

Oh my God, why did I said there would be so many sections? I literally have nothing to say here. What did I do? I went to openshift.com and learned that they use git and I could just push to a private repository and the machine would restart the bot…

Sorry, I don't have more information here…

Finally, I've been writing this whole thing waiting to use this gif:

Get it? The bot is alive…

And just like that the bot is working, now I only have to work improving it:

This is me saying something like: ass and fuck
This is my friends and I adding "butt" to the blacklist

This might be the weekly post, but only if I find nothing that I want to write until next week.