Giter Site home page Giter Site logo

louis70109 / lotify Goto Github PK

View Code? Open in Web Editor NEW
107.0 7.0 12.0 100 KB

LINE Notify API wrapper for Python

Home Page: https://nijialin.com/2020/05/03/%E7%AC%AC%E4%B8%80%E6%AC%A1%E5%AF%AB-python-%E5%A5%97%E4%BB%B6%E7%9A%84%E5%AF%A6%E6%88%B0%E5%85%A8%E8%A8%98%E9%8C%84/

License: MIT License

Python 99.61% Makefile 0.39%
line line-notify sdk lotify python

lotify's Introduction

Lotify - LINE Notify client SDK

License: MIT PRs Welcome Build Status pypi package Python Version GitHub latest commit GitHub stars

๐Ÿ“– Chinese traditional version

Lotify is a LINE Notify client SDK that you can build notification bot quickly.

If your programing language is not python, here had another language:

Usage

First, you need a LINE account and create a LINE Notify channel as following:

create-a-line-notify

Install package

pip install lotify

Here has example - flask-line-notify

Command line

lotify -t YOUR_TOKEN -m 'this is example'

Environment variables

Input those variables in your .env file or OS environment (or using export).

Then you don't need to input any parameters in initialize step.

LINE_NOTIFY_CLIENT_ID
LINE_NOTIFY_CLIENT_SECRET
LINE_NOTIFY_REDIRECT_URI

Initialize instance

  • If you already have Notify environment variables:
from lotify.client import Client

client = Client()
  • else:
from lotify.client import Client

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

Get authorizer link

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

Get access token

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

Get Status

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

Send message

push-notify

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

Send message with Sticker

push-notify-with-sticker

You can find stickerId and stickerPackageId here.

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 Files

send-message-with-image-path

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

Send message with Image url

send-message-with-image-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'}

Revoke access token

revoke-line-notify-token

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

Command Line Interface

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

Contributing

Fork before Clone the repository:

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

First install for development.

pip install -r requirements-dev.txt

Run pytest to make sure the tests pass:

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

Command Line Debug

If you met following logs.

Traceback (most recent call last):
  File "/usr/local/bin/lotify", line 33, in <module>
    sys.exit(load_entry_point('lotify==2.3.2', 'console_scripts', 'lotify')())
  File "/usr/local/bin/lotify", line 25, in importlib_load_entry_point
    return next(matches).load()
StopIteration

Uninstall old package and reinstall.

pip uninstall lotify
pip install lotify

Then StopIteration would go away.

Contributors

License

MIT ยฉ NiJia Lin & Duncan Huang

lotify's People

Contributors

ca-lee avatar louis70109 avatar mirrorshih avatar ragnaok avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

lotify's Issues

Support CLI

Like:

lotify -t MY_TOKEN -m 'this is test message'

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.