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)
pip install line-bot-sdk
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.
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!
[Qiita @ kotamatsuoka: Implement push notifications in Python using the LINE Bot API] (https://qiita.com/kotamatsuoka/items/6f56d0d0a3225160b4d0)
Recommended Posts