A bot memorandum that uses LINE Notify in Python and sends messages to LINE.
The procedure is as follows.
The LINE Notify official website has the following explanation.
When you link with the web service, you will receive a notification from the official account "LINE Notify" provided by LINE. It is possible to link with multiple services and receive notifications even in groups.
By linking with LINE Notify, LINE users will be able to easily receive service notifications.
I will omit it.
Please refer to the following site for e-mail address registration.
import requests
url = "https://notify-api.line.me/api/notify"
access_token = 'xxxxxxxxxxxxxxxx'
class LineNotify:
def __init__(self, url, access_token):
self.url = url
self.headers = {'Authorization': 'Bearer ' + access_token}
def send_message(self, message, image=None, sticker_package_id=None, sticker_id=None):
payload = {
'message': message,
'stickerPackageId': sticker_package_id,
'stickerId': sticker_id
}
files = {}
if image != None:
files = {'imageFile': open(image, 'rb')}
r = requests.post(
self.url,
headers=self.headers,
data=payload,
files=files
)
##Main
if __name__ == '__main__':
bot = LineNotify(url, access_token)
bot.send_message('This message is a test.')
Recommended Posts