-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathapp.py
80 lines (61 loc) · 2.37 KB
/
app.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
import uuid
from flask import Flask, render_template, request, jsonify
import os
from lotify.client import Client
app = Flask(__name__)
CLIENT_ID = os.getenv("LINE_CLIENT_ID")
SECRET = os.getenv("LINE_CLIENT_SECRET")
URI = os.getenv("LINE_REDIRECT_URI")
lotify = Client(client_id=CLIENT_ID, client_secret=SECRET, redirect_uri=URI)
@app.route("/")
def home():
link = lotify.get_auth_link(state=uuid.uuid4())
return render_template("notify_index.html", auth_url=link)
@app.route("/callback")
def confirm():
token = lotify.get_access_token(code=request.args.get("code"))
return render_template("notify_confirm.html", token=token)
@app.route("/notify/send", methods=["POST"])
def send():
payload = request.get_json()
response = lotify.send_message(
access_token=payload.get("token"), message=payload.get("message")
)
return jsonify(result=response.get("message")), response.get("status")
@app.route("/notify/send/sticker", methods=["POST"])
def send_sticker():
payload = request.get_json()
response = lotify.send_message_with_sticker(
access_token=payload.get("token"),
message=payload.get("message"),
sticker_id=630,
sticker_package_id=4,
)
return jsonify(result=response.get("message")), response.get("status")
@app.route("/notify/send/url", methods=["POST"])
def send_url():
payload = request.get_json()
response = lotify.send_message_with_image_url(
access_token=payload.get("token"),
message=payload.get("message"),
image_fullsize=payload.get("url"),
image_thumbnail=payload.get("url"),
)
return jsonify(result=response.get("message")), response.get("status")
@app.route("/notify/send/path", methods=["POST"])
def send_file():
payload = request.get_json()
response = lotify.send_message_with_image_file(
access_token=payload.get("token"),
message=payload.get("message"),
file=open("./test_data/dog.png", "rb"),
)
return jsonify(result=response.get("message")), response.get("status")
@app.route("/notify/revoke", methods=["POST"])
def revoke():
payload = request.get_json()
response = lotify.revoke(access_token=payload.get("token"))
return jsonify(result=response.get("message")), response.get("status")
if __name__ == "__main__":
port = os.environ.get("PORT", 8000)
app.run(host="0.0.0.0", port=port, debug=True)