/ android

Create a quick bot to help you with /r/AndroidDev

In trying to learn how to be a better Android Developer, and not being a serial reddit user (ok fine... lurker), knowing any tips and tricks to following a sub, I stumbled upon the Android Dev subreddit I found really useful. The problem was I couldn't keep up with everything posted there every single time.

What if there was a "Who's hiring" thread that had what I was looking for. What if there was a blog post from someone who's talking about something I had been struggling with? The usual fomo stuff people get - except for Android.

In being a telegram user, I created a bot hooked it up to IFTT...

/** And completely over-engineered this. There's tons of easier ways to do this, but this was so much cooler at the time. Also, why not? **/

I used to get notified of any new post within the sub. At first this was fun. I knew EVERYTHING. But later i decided knowing to the tee when a conference on YouTube was posted wasn't exactly something I needed 24x7x365. Maybe I could set aside time where I could go through the messages and see what's been going on, pin something I want to follow up on, and debate with people within my group what they think of something we both saw was posted etc. It's been great so far in that now that I've pinned the chat group to the top of my list of chats, so i'm always reminded to go and check it out often.

If interested, here is how you can do this yourself:

Setting up your bot:

Create a bot by contacting Botfather. You can find out more on how to do this here.

Once you have your bot, you can decide whether to have it post in a group you create, or to you directly. I prefer the group thing because I can pin stuff to the top of the chat for follow up later, also it's a lot easier to get people involved if you have fellow android devs looking out for new chats. You can also upgrade this to a supergroup to get all the cool group features.

Last step if using a group, is to add the bot to your group.

Getting the chat Id:

Before your bot can post to a group or chat, you need the chat id first. At this point, if you are using a group - best to upgrade to a supergroup here if you plan to, because the chat id changes when the group is upgraded and you will no longer be able to see messages your bot sends.

Now there probably is a better way to do this but so far what i usually do to get the chat id is to send a message to group (making sure the bot is already added), then curl or use a rest api client like postman for chrome to the following url:

https://api.telegram.org/bot<bot_token>/getUpdates

The json response will have a section with the chat id in it such as below:

    "ok": true,
    "result": [
        {
//some stuff above thit part, then:
           "chat": {
                   "id": -99999999,
                    "title": "Android News",
                    "type": "group",
                    "all_members_are_administrators": true //if this is for you
                },
//further info

Once you have the chat id, it's time to head over to IFTTT.

IFTTT:

Once logged into the site, you select the new applet function and you are presented with the "If this then that" panel:

If_this_then_that

Click on the +this then search for the reddit applet and fill out as below:

trigger2

Then for the last part of the trigger, you search for the web-hook option:

![trigger_3_web](/content/images/2017/07/trigger3.jpg)

Then fill out as below:

trigger_4_1

trigger_4_2

Then all done.

The final chat looks like this:

(Note the pinned message of a post I find interesting, I can follow up at a later date as well)

dev_chat

The nice thing about this setup is I know there is a dedicated IFTTT bot function that you can use, but this way is so much more flexible not just for reddit but for other purposes when you have bots doing anything else other than IFTTT. For example, using a summary api , and a digitalocean droplet, I now have a bot, much like the one on reddit, that can tldr messages:

tldr_bot

And of course this always gets abused in groups :)

Vusi Moyo

Some guy that found code on the internet and is treating it like play dough

Read More