Skip to content

Instantly share code, notes, and snippets.

@jiankaiwang
Created December 29, 2017 02:13
Show Gist options
  • Save jiankaiwang/2ce0de6b1c27b2475ca3d936b909f1f5 to your computer and use it in GitHub Desktop.
Save jiankaiwang/2ce0de6b1c27b2475ca3d936b909f1f5 to your computer and use it in GitHub Desktop.
Send information to the specific line group.
# -*- coding: utf-8 -*-
"""
author : JianKai Wang
description : send info to the specific line group
date : Dec 2017
Line Notify : https://notify-bot.line.me
document :
* line sticker : https://devdocs.line.me/files/sticker_list.pdf
Notice :
* Add the official account (LINE Notify) into the group
receiving the notification.
"""
# -----------------------------------------------------------------------------
# you can comment it, there is only one function using it (sendMsgByLineTool)
import lineTool
# -----------------------------------------------------------------------------
import requests
def sendMsgByLineTool(getToken, getMsg):
lineTool.lineNotify(getToken, getMsg)
def sendMsgByOriginPackage(getToken, getMsg):
url = 'https://notify-api.line.me/api/notify'
headers = {
'Authorization': 'Bearer ' + getToken,
'Content-Type' : 'application/x-www-form-urlencoded'
}
payload = {'message': getMsg}
r = requests.post(url, headers = headers, params = payload)
return r
def sendMsgAndStickerByOriPkg(getToken, getMsg, getStickerPkgId, getStickerId):
url = "https://notify-api.line.me/api/notify"
headers = {
"Authorization": "Bearer " + getToken
}
payload = {\
"message": getMsg, \
"stickerPackageId": getStickerPkgId, \
'stickerId': getStickerId
}
r = requests.post(url, headers = headers, params = payload)
return r
def sendMsgAndImgByOriPkg(getToken, getMsg, getPicUri):
url = "https://notify-api.line.me/api/notify"
headers = {
"Authorization": "Bearer " + getToken
}
payload = {'message': msg}
files = {'imageFile': open(getPicUri, 'rb')}
r = requests.post(url, headers = headers, params = payload, files = files)
return r
# necessary
token = '(Put in your token key)'
# only send the message
msg = 'This is the message.'
print(sendMsgByOriginPackage(token, msg).status_code)
# send the message and the sticker
msg = "send the message and the sticker"
stickerPId = 1
stickerId = 114
print(sendMsgAndStickerByOriPkg(token, msg, stickerPId, stickerId).status_code)
# send the message and the image
msg = "send the message and the image"
imgPath = "./img/example.png"
print(sendMsgAndImgByOriPkg(token, msg, imgPath).status_code)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment