{"id":477,"date":"2022-11-14T00:58:07","date_gmt":"2022-11-13T16:58:07","guid":{"rendered":"https:\/\/unama.website\/?p=477"},"modified":"2022-12-03T18:25:28","modified_gmt":"2022-12-03T10:25:28","slug":"line-notify-python","status":"publish","type":"post","link":"https:\/\/unama.website\/?p=477","title":{"rendered":"Line Notify (Python)"},"content":{"rendered":"\n<p>Step 1. go to my page on <a href=\"https:\/\/notify-bot.line.me\/en\/\">LINE Notify<\/a><\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" loading=\"lazy\" width=\"1024\" height=\"311\" src=\"https:\/\/unama.website\/wp-content\/uploads\/2022\/11\/image-1024x311.png\" alt=\"\" class=\"wp-image-478\" srcset=\"https:\/\/unama.website\/wp-content\/uploads\/2022\/11\/image-1024x311.png 1024w, https:\/\/unama.website\/wp-content\/uploads\/2022\/11\/image-300x91.png 300w, https:\/\/unama.website\/wp-content\/uploads\/2022\/11\/image-768x233.png 768w, https:\/\/unama.website\/wp-content\/uploads\/2022\/11\/image-1536x466.png 1536w, https:\/\/unama.website\/wp-content\/uploads\/2022\/11\/image-2048x621.png 2048w, https:\/\/unama.website\/wp-content\/uploads\/2022\/11\/image-604x183.png 604w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>Step 2. get Issuance Sceptre<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" loading=\"lazy\" width=\"1024\" height=\"348\" src=\"https:\/\/unama.website\/wp-content\/uploads\/2022\/11\/image-1-1024x348.png\" alt=\"\" class=\"wp-image-479\" srcset=\"https:\/\/unama.website\/wp-content\/uploads\/2022\/11\/image-1-1024x348.png 1024w, https:\/\/unama.website\/wp-content\/uploads\/2022\/11\/image-1-300x102.png 300w, https:\/\/unama.website\/wp-content\/uploads\/2022\/11\/image-1-768x261.png 768w, https:\/\/unama.website\/wp-content\/uploads\/2022\/11\/image-1-1536x522.png 1536w, https:\/\/unama.website\/wp-content\/uploads\/2022\/11\/image-1-604x205.png 604w, https:\/\/unama.website\/wp-content\/uploads\/2022\/11\/image-1.png 1836w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>Step 3. name your token and select chat room and get your token<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" loading=\"lazy\" width=\"638\" height=\"1024\" src=\"https:\/\/unama.website\/wp-content\/uploads\/2022\/11\/image-2-638x1024.png\" alt=\"\" class=\"wp-image-480\" srcset=\"https:\/\/unama.website\/wp-content\/uploads\/2022\/11\/image-2-638x1024.png 638w, https:\/\/unama.website\/wp-content\/uploads\/2022\/11\/image-2-187x300.png 187w, https:\/\/unama.website\/wp-content\/uploads\/2022\/11\/image-2-168x270.png 168w, https:\/\/unama.website\/wp-content\/uploads\/2022\/11\/image-2.png 682w\" sizes=\"(max-width: 638px) 100vw, 638px\" \/><\/figure>\n\n\n\n<p>Step 4. add line notify to your friend group and  add line notify to the chat room you want to use line notify<\/p>\n\n\n\n<p>Step 5. test API code<\/p>\n\n\n\n<p>run this command to check if your bot can send msg to the chat room<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>curl -X POST \\\n     -H 'Authorization: Bearer YOUR TOKEN' \\\n     -F 'message=foobar' \\\n     https:&#47;&#47;notify-api.line.me\/api\/notify<\/code><\/pre>\n\n\n\n<p>Step 6. python example code with sticker<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>import requests, os\n\n\"\"\"\n\u767c\u9001 Line Notify \u8a0a\u606f + \u8868\u60c5\u7b26\u865f\n\"\"\"\ndef lineNotify(token, msg, stickerPackageId, stickerId):\n    url = \"https:\/\/notify-api.line.me\/api\/notify\"\n    headers = {\n        \"Authorization\": \"Bearer \" + token\n    }\n\n    payload = {\"message\": msg, \"stickerPackageId\": stickerPackageId, 'stickerId': stickerId}\n    r = requests.post(url, headers = headers, params = payload)\n    return r.status_code\n\n\ntoken = \"tI1rpxhKT28IPFL6bP8T2Ry7Js3uZQiOctChrnUsIiL\"\nmsg = \"Hello World!\"\nstickerPackageId = 11537\nstickerId = 52002749\n\nlineNotify(token, msg, stickerPackageId, stickerId)<\/code><\/pre>\n\n\n\n<p>Step 7. you can change sticker by searching sticker ID in <a rel=\"noreferrer noopener\" href=\"https:\/\/developers.line.biz\/en\/docs\/messaging-api\/sticker-list\/#specify-sticker-in-message-object\" target=\"_blank\">List of available stickers<\/a><\/p>\n\n\n\n<p>Step 8. you can use cron job to schedule the python code execution<\/p>\n\n\n\n<p>I will write an article about crontab later&#8230;.<\/p>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Step 1. go to my page on LINE Notify Step 2. get Issuance Sceptre Step 3. name y&#8230;<\/p>\n<p class=\"read-more\"><a class=\"btn btn-default\" href=\"https:\/\/unama.website\/?p=477\"> Read More<span class=\"screen-reader-text\">  Read More<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[13,7,11],"tags":[],"_links":{"self":[{"href":"https:\/\/unama.website\/index.php?rest_route=\/wp\/v2\/posts\/477"}],"collection":[{"href":"https:\/\/unama.website\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unama.website\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unama.website\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unama.website\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=477"}],"version-history":[{"count":2,"href":"https:\/\/unama.website\/index.php?rest_route=\/wp\/v2\/posts\/477\/revisions"}],"predecessor-version":[{"id":483,"href":"https:\/\/unama.website\/index.php?rest_route=\/wp\/v2\/posts\/477\/revisions\/483"}],"wp:attachment":[{"href":"https:\/\/unama.website\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=477"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unama.website\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=477"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unama.website\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=477"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}