lotify

LINE Notify API wrapper for Python

MIT License

Downloads
2K
Stars
108

Lotify - LINE Notify 客戶端 SDK

English version

Lotify 是個讓你可以快速建立 Notify 機器人的 LINE Notify 客戶端 SDK。

如果你不是使用 Python,這裡有其他選擇:

如何使用

你需要有一個 LINE 帳號 並建立一個 Notify 服務:

安裝套件

pip install lotify

你可以在這裡找到範例程式 - flask-line-notify

環境變數(Environment variables)

.env 檔案中設定以下參數或使用 export 在 OS 環境中設定,這樣你就不用在 初始化 時設定任何參數。

LINE_NOTIFY_CLIENT_ID
LINE_NOTIFY_CLIENT_SECRET
LINE_NOTIFY_REDIRECT_URI

初始化物件

  • 如果你已經設定好 Notify 的環境變數:
from lotify.client import Client

client = Client()
  • 否則:
from lotify.client import Client

client = Client(
    client_id='YOUR_CLIENT_ID',
    client_secret='YOUR_CLIENT_SECRET',
    redirect_uri='YOUR_URI'
)

取得授權網址

link = client.get_auth_link(state='RANDOM_STRING')
print(link)
# https://notify-bot.line.me/oauth/authorize?scope=notify&response_type=code&client_id=QxUxF..........i51eITH&redirect_uri=http%3A%2F%2Flocalhost%3A5000%2Fnotify&state=foo

取得 access token

access_token = client.get_access_token(code='NOTIFY_RESPONSE_CODE')
print(access_token)
# N6g50DiQZk5Xh...25FoFzrs2npkU3z

取得狀態

status = client.status(access_token='YOUR_ACCESS_TOKEN')
print(status)
# {'status': 200, 'message': 'ok', 'targetType': 'USER', 'target': 'NiJia Lin'}

傳送訊息

response = client.send_message(access_token='YOUR_ACCESS_TOKEN', message='This is notify message')
print(response)
# {'status': 200, 'message': 'ok'}

傳送訊息加貼圖

你可以在 這裡 找到 stickerId 和 stickerPackageId

response = client.send_message_with_sticker(
    access_token='YOUR_ACCESS_TOKEN',
    message='This is notify message',
    sticker_id=1,
    sticker_package_id=1)
print(response)
# {'status': 200, 'message': 'ok'}

傳送訊息加檔案

image = client.send_message_with_image_file(
    access_token='YOUR_ACCESS_TOKEN',
    message='This is notify message',
    file=open('./test_image.png', 'rb')
)
print(image)
# {'status': 200, 'message': 'ok'}

傳送訊息加圖片(URL模式)

image = client.send_message_with_image_url(
    access_token='YOUR_ACCESS_TOKEN',
    message='This is notify message',
    image_thumbnail='https://i.imgur.com/RhvwZVm.png',
    image_fullsize='https://i.imgur.com/RhvwZVm.png',
)
print(image)
# {'status': 200, 'message': 'ok'}

撤銷 access token

revoke = client.revoke(access_token='YOUR_ACCESS_TOKEN')
print(revoke)
# {'status': 200, 'message': 'ok'}

在命令列中使用

lotify --help
-t, --access_token TEXT  access token  [required]
-m, --message TEXT       message to send  [required]
-u, --image-url TEXT     image url to send
-f, --image-file TEXT    image file path to send

貢獻指南

請先 Fork 再 Clone:

git clone [email protected]:your-username/line-notify.git

首先,安裝開發環境。

pip install -r requirements-dev.txt

執行 pytest 確定通過測試:

cd line-notify/
python -m tox
python -m pytest --flake8 tests/

授權條款

MIT © NiJia Lin & Duncan Huang & Samuel C.A. Lee

Package Rankings
Top 7.52% on Pypi.org
Badges
Extracted from project README
License: MIT PRs Welcome Build Status pypi package Python Version
Related Projects