Build a LINE Chatbot in Python

Yeonho Park
BotHub.Studio
Published in
3 min readNov 1, 2018

Create LINE Bot

  1. Log in to LINE’s developer website and click ‘Add new provider’ menu
  1. Click ‘Create New Provider’

2. Enter a ‘Provider name’ and click ‘Confirm’

3. Click ‘Create Channel’ under Messaging API

4. Enter an ‘App name’ and ‘App description’

5. Choose a ‘Plan’ and ‘Category’ , ‘Subcategory’

6. Enter your Email address and click ‘Confirm’

7. Confirm the terms of use options and click ‘Create’

Submit LINE credentials to Bothub

# Gather credentials

  1. Select a created ‘Messaing API’

2. Click ‘Issue’ button at the ‘Channel access token’

3. Set value to ‘0 hours’ and click ‘Issue’

4. The below information are required for configuration of your LINE Bot.

  • Channel ID
  • Channel secret
  • Channel access token

# Setup Hosting for Bot and submit credentials

First, create an account on BotHub.Studio, a chatbot hosting service for developers, and install CLI tool using the command below:

$ pip install bothub-cli

Run configure next:

$ bothub configure

Create a project directory:

$ mkdir MyBot
$ cd MyBot
$ bothub init

A template code will be generated after init finished.

| — bothub
| | — bot.py
| ` — __init__.py
| — bothub.yml
| — requirements.txt
` — tests

Now we connect with ‘LINE’ channel:

The ‘URL’ s that is result of command will be used ‘LINE’ setting page:

1) Enter command below command at the prompt.

$ bothub channel add line --channel-id=<channel id> \
--channel-secret=<channel secret> \
--channel-access-token=<channel access token>

2) Printed URL is required for LINE setting.

LINE Webhook Enabling

  1. Change to ‘Enabled’ in ‘Use webhooks’
  2. Enter a ‘Webhook URL’ from upper result (Do not enter twice ‘https://’)

LINE Chatbot Test

  1. Prepare QR code in ‘Messaging API’ -> ‘Channel settings’
  2. Select a QR code at the friend add menu and add friend.

If you do not want to use ‘Auto-reply’ or ‘Greeting’ message,
please disable it.

Should you have any questions, please feel free to contact bothub@bothub.studio anytime.

--

--