-
Notifications
You must be signed in to change notification settings - Fork 0
/
profile.py
95 lines (89 loc) · 3.13 KB
/
profile.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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
from flask import request
import requests
import database
import app
def verify_fb_token(token_sent, verify_token):
#take token sent by facebook and verify it matches the verify token you sent
#if they match, allow the request, else return an error
if token_sent == verify_token:
return request.args.get("hub.challenge")
return 'Invalid verification token'
def parse_postback(postback, user_id):
if postback == "JOIN_PAYLOAD":
app.send_message(user_id, "Work in Progress...")
elif postback == "LEAVE_PAYLOAD":
database.leave_room(user_id)
elif postback == "NAME_PAYLOAD":
app.send_message(user_id, "Work in Progress...")
elif postback == "ROOM_INFO_PAYLOAD":
room = database.get_user_room(user_id)
if room is None:
app.send_message(user_id, "You're not currently in a room. Please join one.")
else:
app.send_message(user_id, "You're currently in room: " + room)
elif postback == "COMMAND_INFO_PAYLOAD":
database.get_commands(user_id)
def setup_profile(verify_token):
url = "https://graph.facebook.com/v2.6/me/messenger_profile?access_token={0}".format(verify_token)
profile = {
"greeting": [
{
"locale": "default",
"text": "Hello!"
},
{
"locale": "en_US",
"text": "Hello! This is a test"
}
],
"get_started": {
"payload": "GET_STARTED_PAYLOAD"
},
"whitelisted_domains": [
"https://facebook.com/"
],
"persistent_menu":
[
{
"locale":"default",
"composer_input_disabled": False,
"call_to_actions":[
{
"title":"Room Options",
"type":"nested",
"call_to_actions":
[
{
"title":"Join a Room",
"type":"postback",
"payload":"JOIN_PAYLOAD"
},
{
"title":"Leave Room",
"type":"postback",
"payload":"LEAVE_PAYLOAD"
},
{
"title":"Room Information",
"type":"postback",
"payload":"ROOM_INFO_PAYLOAD"
}
]
},
{
"title": "Set Name",
"type": "postback",
"payload": "NAME_PAYLOAD"
},
{
"type":"web_url",
"title":"Set Language",
"url":"http://www.messenger.com/",
"webview_height_ratio":"full"
}
]
}
]
}
req = requests.post(url, json=profile)
return req.json()