Skip to content

Commit 0569f71

Browse files
committed
新增 Python Line Bot 如何一次傳給多人訊息?手把手教學 Part 6 程式碼
1 parent 19471bf commit 0569f71

File tree

4 files changed

+39
-0
lines changed

4 files changed

+39
-0
lines changed

LineBot/Chapter_5/Procfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
web: python app.py

LineBot/Chapter_5/README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#
2+
文章名稱:Python Line Bot 如何一次傳給多人訊息?手把手教學 Part 6
3+
4+
文章連結:https://shareboxnow.com/line-bot-python-part-6/
5+
6+
程式碼位置:https://github.com/MarkwwLiu/PythonBasicTeaching/tree/master/LineBot/Chapter_5

LineBot/Chapter_5/app.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
from flask import Flask, request, abort
2+
import json
3+
from linebot import (
4+
LineBotApi, WebhookHandler
5+
)
6+
from linebot.exceptions import (
7+
InvalidSignatureError
8+
)
9+
from linebot.models import *
10+
11+
app = Flask(__name__)
12+
13+
# Channel Access Token
14+
line_bot_api = LineBotApi({YOU_Channel_Access Token})
15+
# Channel Secret
16+
handler = WebhookHandler({YOU_Channel_Secret})
17+
18+
user_id = {YOU_USER_ID}
19+
20+
21+
@app.route("/broadcast_function/<string:broadcast_text_str>")
22+
def broadcast_message(broadcast_text_str):
23+
line_bot_api.broadcast(TextSendMessage(text = broadcast_text_str))
24+
return 'OK'
25+
26+
import os
27+
28+
if __name__ == "__main__":
29+
port = int(os.environ.get('PORT', 5000))
30+
app.run(host = '0.0.0.0', port = port, debug = True)

LineBot/Chapter_5/requirements.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
line-bot-sdk
2+
flask

0 commit comments

Comments
 (0)