Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/louis70109/lotify

LINE Notify API wrapper for Python
https://github.com/louis70109/lotify

line line-notify lotify python sdk

Last synced: 6 days ago
JSON representation

LINE Notify API wrapper for Python

Awesome Lists containing this project

README

        

# Lotify - LINE Notify 客戶端 SDK

[![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](https://opensource.org/licenses/MIT)
[![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg)](https://github.com/louis70109/line-notify#contributing)
[![Build Status](https://travis-ci.com/louis70109/lotify.svg?branch=master)](https://travis-ci.org/louis70109/lotify)
[![pypi package](https://badge.fury.io/py/lotify.svg)](https://badge.fury.io/py/lotify)
[![Python Version](https://img.shields.io/badge/Python-%3E%3D%203.5-blue.svg)](https://badge.fury.io/py/lotify)

[English version](https://github.com/louis70109/lotify/blob/master/README.md)

**Lotify** 是個讓你可以快速建立 Notify 機器人的 [LINE Notify](https://notify-bot.line.me/doc/en/) 客戶端 SDK。

![](https://i.imgur.com/Rms5ZNG.png)

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

- [Ruby](https://github.com/etrex/lotify)
- [PHP](https://github.com/eric0324/lotify)

# 如何使用

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

![create-a-line-notify](https://i.imgur.com/m9q4jLOl.png)

## 安裝套件

```
pip install lotify
```

> 你可以在這裡找到範例程式 - [flask-line-notify](https://github.com/louis70109/flask-line-notify)

## 環境變數(Environment variables)

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

```
LINE_NOTIFY_CLIENT_ID
LINE_NOTIFY_CLIENT_SECRET
LINE_NOTIFY_REDIRECT_URI
```

## 初始化物件

- 如果你已經設定好 Notify 的環境變數:

```python
from lotify.client import Client

client = Client()
```

- 否則:

```python
from lotify.client import Client

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

## 取得授權網址

```python
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

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

## 取得狀態

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

## 傳送訊息

![push-notify](https://i.imgur.com/RhvwZVm.png)

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

## 傳送訊息加貼圖

![push-notify-with-sticker](https://i.imgur.com/EWpZahk.png)

你可以在 [這裡](https://devdocs.line.me/files/sticker_list.pdf) 找到 stickerId 和 stickerPackageId

```python
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'}
```

## 傳送訊息加檔案

![send-message-with-image-path](https://i.imgur.com/ESCrk8b.png)

```python
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模式)

![send-message-with-image-url](https://i.imgur.com/0Lxatu9.png)

```python
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-line-notify-token](https://i.imgur.com/7GAAzOi.png)

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

## 在命令列中使用
```commandline
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](https://github.com/louis70109/line-notify/blob/master/LICENSE) © [NiJia Lin](https://nijialin.com/about/) & [Duncan Huang](https://github.com/ragnaok) & [Samuel C.A. Lee](https://github.com/CA-Lee)