Creating your first LINE Bot

Abhishta Gatya
Source https://developers.line.me/en/services/messaging-api/

If you live somewhere in Asia, you might’ve heard of or even use LINE Messenger on a daily basis. Now what I want to introduce to you and what makes LINE Messenger different from its competitors are “Official Accounts”. Official Accounts are Accounts that can be created by a company or even individuals to mass-send messages to users who have become friends with their accounts, and also receiving post articles and more. This account can be operated by individuals, groups or even programs that runs with the LINE Bot SDK (Standard Developer Kit)and hooking it up with the Messaging API.

Now if you want to operate the account yourself or with a group, it is pretty easy. You can just open up LINE@ and get started or if you’re at your smartphone right now, go ahead install LINE@ on Android Play Store or Apple’s App Store. Despite the not-so-good review on both platforms, I still see it very useful to send urgent messages or even tweak around the settings.

Lets Get Coding

Now if you don’t want all that being operated yourself or others, you can always create a program to do it for you. So I’m going to kind of guide you through creating your first bot for LINE. Keep in mind that this is not a completely beginner tutorial, but LINE provides a wide selections of programming language to code your bot (See here). Also a little bit of knowledge about Heroku and GitHub.

Now what I’m going to guide you through is doing it in Python, because I provided a starter kit for python (See here). I find it really easy to create it in Python and of course we will use the Official Bot SDK provided by LINE.

Once you have followed the instructions in the documentation and clone the repository from GitHub, you have to go to LINE Developers to create your channel, create your bot and hooking it up with the Messaging API.

You can follow the guide here provided by LINE Developers.

Once you have created your channel and bot, you will see your channel secret and channel access token being displayed (click ‘issue’ if not displayed).

Copy and paste both channel secret and channel access token to your project file called ‘app.py’ and then save it. Now we are going to try to deploy our project folder to Heroku. Make sure to create your heroku account and if you are on Windows, download the Heroku CLI. If you are on Linux or MacOS, you can see how to get started here.

Once you have created your Heroku account, its time to deploy our project to Heroku. Go ahead and follow the code below :

$ git commit -a -m "Changed Token"
$ heroku create [APP-NAME]
$ git push heroku master

Now once your code has been deployed to heroku, you can open up the URL :

https://[APP-NAME].herokuapp.com/

Or go open up your Heroku dashboard and click ‘open app’ and it will open up your heroku app. Now what you want to do with this is add ‘callback’ to the end of the URL so it will look like this :

https://[APP-NAME].herokuapp.com/callback

This we will put inside our Webhook URL in the LINE Developers Bot Options you just created before. Once that is done, make sure to enable webhooks option otherwise it won’t work. And that’s about it, you can add your bot using the QR Code provided by LINE and continue tweaking your bot.


Preview of dotPython

I just want to share something that I’ve created using the LINE Bot SDK, I’ve created a learning platform that teaches programming via LINE Bot. You can try it out and learn the basics of programming anywhere for free. You can also join our group over at LINE with over 500+ Students and counting sharing information and knowledge in the world of programming.

You can click here to join in with potentially thousands of students joining in or scan the bar code below :

QR Code to dotPython

Author : Abhishta Gatya

Catch me on GitHub to see more like this

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade