[Python] Make your own LINE bot

Caution This article introduces the process of making a ** LINE bot for yourself ** in Python. If you limit it to this purpose, creating a LINE bot will be very easy. (Usage example: Notify the end of a time-consuming script via LINE)

Python API installation

pip install line-bot-sdk

Registration to LINE Developers (Messaging API), acquisition of necessary items

The information required here is

--Channel access token: From Messaging API settings --Destination user ID: ** Register with the account you want to send to (yourself) **, you can check the destination ID with Basic settings> Your user ID (lower). ――It is different from the ID (the one used for friend search etc.) seen from the profile of the smartphone

If you want to send to other users --Get Channel secret from LINE Developers --Get user ID in response to events such as follow and message reception Is additionally required.

Python code

from linebot import LineBotApi
from linebot.models import TextSendMessage

LINE_CHANNEL_ACCESS_TOKEN = 'Channel access token obtained above'
LINE_USER_ID_TO           = 'User ID of the destination obtained above'

def send_message(message=None):
    '''
    Args:
        message (str): default, hello
    '''
    if not message: message = 'hello'
    line_bot_api = LineBotApi(LINE_CHANNEL_ACCESS_TOKEN)
    messages     = TextSendMessage(text=message)
    line_bot_api.push_message(LINE_USER_ID_TO, messages=messages)
    return

if __name__ == "__main__":
    send_message() # hello
    send_message('goodbye') # goodbye

only this!

reference

[Qiita @ kotamatsuoka: Implement push notifications in Python using the LINE Bot API] (https://qiita.com/kotamatsuoka/items/6f56d0d0a3225160b4d0)

Recommended Posts

[Python] Make your own LINE bot
Make LINE BOT (Echolalia)
Make your own module quickly with setuptools (python)
Make a LINE BOT (chat)
[For play] Let's make Yubaba a LINE Bot (Python)
[Super easy] Let's make a LINE BOT with Python.
Make python segfault in one line
Make your own manual. [Linux] [man]
[Python] logging in your own module
Create your own Linux commands in Python
[LLDB] Create your own command in Python
Easily use your own functions in Python
[Python] Package and distribute your own modules
Make your own PC for deep learning
[Python] Register your own library on PyPI
[Python] [LINE Bot] Create a parrot return LINE Bot
Until you install your own Python library
Publish your own Python library with Homebrew
Let's make a Twitter Bot with Python!
Get your own IP address in Python
I tried to make my own high school girl BOT with Rinna style with LINE BOT (Python & Heroku)
Python beginners decided to make a LINE bot with Flask (Flask rough commentary)
Make your own NOAA / GOES familiar X-ray flux 3days plot in Python
LINE heroku python
Try to make your own AWS-SDK with bash
[Python] Implement your own list-like class using collections.UserList
Make a Twitter trend bot with heroku + Python
Create a LINE BOT with Minette for Python
LINE BOT with Python + AWS Lambda + API Gateway
Make a rock-paper-scissors game in one line (python)
Import your own modules in Grasshopper's Python development
Make a LINE WORKS bot with Amazon Lex
python: Use your own class for numpy ndarray
Make your own music player with Bottle0.13 + jPlayer2.5!
Make your Python environment "easy" with VS Code
Flow of creating your own package with setup.py with python
Create your own exception
Memo to create your own Box with Pepper's Python
Create your own Big Data in Python for validation
Make a morphological analysis bot loosely with LINE + Flask
Make your python CUI application an app for mac
[Introduction to Udemy Python 3 + Application] 66. Creating your own exceptions
Take your own peak memory usage on Linux & Python
Create your own Random Dot Stereogram (RDS) in Python.
Try to improve your own intro quiz in Python
Let's call your own C ++ library with Python (Preferences)
Make a parrot return LINE Bot on AWS Cloud9
[Blender × Python] Create your own function & summary so far
Use the CASA Toolkit in your own Python environment
[Python] Using Line API [1st Creation of Beauty Bot]
I made a LINE BOT with Python and Heroku
LINE BOT if ~ stumbled
[Road to intermediate Python] Define in in your own class
Call your own python module from the ROS package
Make Python segfault on one line without using ctypes
Make Jupyter Notebook your own: Change background and icons
[LINE Messaging API] Create parrot return BOT with Python
Make a LINE bot with GoogleAppEngine / py. Simple naked version
Until you can install your own Python library with pip
Try sorting your own objects with priority queue in Python
Run the intellisense of your own python library with VScode.