-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathecho.py
More file actions
53 lines (45 loc) · 1.29 KB
/
echo.py
File metadata and controls
53 lines (45 loc) · 1.29 KB
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
from flask import Flask, request
import json
import requests
app = Flask(__name__)
@app.route('/')
def index():
return "<p>Hello World!</p>"
@app.route('/callback', methods=['POST'])
def callback():
json_line = request.get_json()
json_line = json.dumps(json_line)
decoded = json.loads(json_line)
user = decoded['result'][0]['content']['from']
text = decoded['result'][0]['content']['text']
#print(json_line)
print("使用者:",user)
print("內容:",text)
sendText(user,text)
return ''
def sendText(user, text):
LINE_API = 'https://trialbot-api.line.me/v1/events'
CHANNEL_ID = '你的ID'
CHANNEL_SERECT = '你的金鑰'
MID = '你的MID'
headers = {
'Content-Type': 'application/json; charset=UTF-8',
'X-Line-ChannelID': CHANNEL_ID,
'X-Line-ChannelSecret': CHANNEL_SERECT,
'X-Line-Trusted-User-With-ACL': MID
}
data = json.dumps({
"to": [user],
"toChannel":1383378250,
"eventType":"138311608800106203",
"content":{
"contentType":1,
"toType":1,
"text":text
}
})
#print("送出資料:",data)
r = requests.post(LINE_API, headers=headers, data=data)
#print(r.text)
if __name__ == '__main__':
app.run(debug=True)