Line Notify (Python)

Line Notify (Python)

Step 1. go to my page on LINE Notify

Step 2. get Issuance Sceptre

Step 3. name your token and select chat room and get your token

Step 4. add line notify to your friend group and add line notify to the chat room you want to use line notify

Step 5. test API code

run this command to check if your bot can send msg to the chat room

curl -X POST \
     -H 'Authorization: Bearer YOUR TOKEN' \
     -F 'message=foobar' \
     https://notify-api.line.me/api/notify

Step 6. python example code with sticker

import requests, os

"""
發送 Line Notify 訊息 + 表情符號
"""
def lineNotify(token, msg, stickerPackageId, stickerId):
    url = "https://notify-api.line.me/api/notify"
    headers = {
        "Authorization": "Bearer " + token
    }

    payload = {"message": msg, "stickerPackageId": stickerPackageId, 'stickerId': stickerId}
    r = requests.post(url, headers = headers, params = payload)
    return r.status_code


token = "tI1rpxhKT28IPFL6bP8T2Ry7Js3uZQiOctChrnUsIiL"
msg = "Hello World!"
stickerPackageId = 11537
stickerId = 52002749

lineNotify(token, msg, stickerPackageId, stickerId)

Step 7. you can change sticker by searching sticker ID in List of available stickers

Step 8. you can use cron job to schedule the python code execution

I will write an article about crontab later….

發佈留言

發佈留言必須填寫的電子郵件地址不會公開。 必填欄位標示為 *