Spaces:
Runtime error
Runtime error
Greg Thompson
commited on
Commit
•
a8ebc1e
1
Parent(s):
a901bc8
Add feature to make message based on conditions
Browse files
mathtext_fastapi/conversation_manager.py
CHANGED
@@ -8,11 +8,6 @@ load_dotenv()
|
|
8 |
|
9 |
# os.environ.get('SUPABASE_URL')
|
10 |
|
11 |
-
def parse_data(data):
|
12 |
-
data_bytes = requests.body
|
13 |
-
data_decoded = data_bytes.decode()
|
14 |
-
data_json = json.loads(data_decoded)
|
15 |
-
return data_json
|
16 |
|
17 |
def generate_message(data_json):
|
18 |
""" pending
|
@@ -47,7 +42,30 @@ def generate_message(data_json):
|
|
47 |
print("DATA JSON")
|
48 |
print(data_json)
|
49 |
|
50 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
51 |
"to": whatsapp_id,
|
52 |
# "to": "alan",
|
53 |
"type": "interactive",
|
@@ -55,7 +73,7 @@ def generate_message(data_json):
|
|
55 |
"type": "button",
|
56 |
# "header": { },
|
57 |
"body": {
|
58 |
-
"text": "
|
59 |
},
|
60 |
# "footer": { },
|
61 |
"action": {
|
@@ -64,14 +82,14 @@ def generate_message(data_json):
|
|
64 |
"type": "reply",
|
65 |
"reply": {
|
66 |
"id": "inquiry-yes",
|
67 |
-
"title": "
|
68 |
}
|
69 |
},
|
70 |
{
|
71 |
"type": "reply",
|
72 |
"reply": {
|
73 |
"id": "inquiry-no",
|
74 |
-
"title": "
|
75 |
}
|
76 |
}
|
77 |
]
|
@@ -79,6 +97,39 @@ def generate_message(data_json):
|
|
79 |
}
|
80 |
}
|
81 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
82 |
r = requests.post(f'https://whatsapp.turn.io/v1/messages', data=json.dumps(data), headers=headers)
|
83 |
print("==================")
|
84 |
print("Headers")
|
|
|
8 |
|
9 |
# os.environ.get('SUPABASE_URL')
|
10 |
|
|
|
|
|
|
|
|
|
|
|
11 |
|
12 |
def generate_message(data_json):
|
13 |
""" pending
|
|
|
42 |
print("DATA JSON")
|
43 |
print(data_json)
|
44 |
|
45 |
+
user_message = data_json['message']['text']['body']
|
46 |
+
|
47 |
+
if user_message == 'add':
|
48 |
+
data = {
|
49 |
+
"preview_url": false,
|
50 |
+
"recipient_type": "individual",
|
51 |
+
"to": whatsapp_id,
|
52 |
+
"type": "text",
|
53 |
+
"text": {
|
54 |
+
"body": "What's 2+2?"
|
55 |
+
}
|
56 |
+
}
|
57 |
+
elif user_message == 'substract':
|
58 |
+
data = {
|
59 |
+
"preview_url": false,
|
60 |
+
"recipient_type": "individual",
|
61 |
+
"to": whatsapp_id,
|
62 |
+
"type": "text",
|
63 |
+
"text": {
|
64 |
+
"body": "What's 1-1?"
|
65 |
+
}
|
66 |
+
}
|
67 |
+
else:
|
68 |
+
data = {
|
69 |
"to": whatsapp_id,
|
70 |
# "to": "alan",
|
71 |
"type": "interactive",
|
|
|
73 |
"type": "button",
|
74 |
# "header": { },
|
75 |
"body": {
|
76 |
+
"text": "Please choose one of the following options."
|
77 |
},
|
78 |
# "footer": { },
|
79 |
"action": {
|
|
|
82 |
"type": "reply",
|
83 |
"reply": {
|
84 |
"id": "inquiry-yes",
|
85 |
+
"title": "add"
|
86 |
}
|
87 |
},
|
88 |
{
|
89 |
"type": "reply",
|
90 |
"reply": {
|
91 |
"id": "inquiry-no",
|
92 |
+
"title": "subtract"
|
93 |
}
|
94 |
}
|
95 |
]
|
|
|
97 |
}
|
98 |
}
|
99 |
|
100 |
+
|
101 |
+
# data = {
|
102 |
+
# "to": whatsapp_id,
|
103 |
+
# # "to": "alan",
|
104 |
+
# "type": "interactive",
|
105 |
+
# "interactive": {
|
106 |
+
# "type": "button",
|
107 |
+
# # "header": { },
|
108 |
+
# "body": {
|
109 |
+
# "text": "Did I answer your question?"
|
110 |
+
# },
|
111 |
+
# # "footer": { },
|
112 |
+
# "action": {
|
113 |
+
# "buttons": [
|
114 |
+
# {
|
115 |
+
# "type": "reply",
|
116 |
+
# "reply": {
|
117 |
+
# "id": "inquiry-yes",
|
118 |
+
# "title": "Yes"
|
119 |
+
# }
|
120 |
+
# },
|
121 |
+
# {
|
122 |
+
# "type": "reply",
|
123 |
+
# "reply": {
|
124 |
+
# "id": "inquiry-no",
|
125 |
+
# "title": "No"
|
126 |
+
# }
|
127 |
+
# }
|
128 |
+
# ]
|
129 |
+
# }
|
130 |
+
# }
|
131 |
+
# }
|
132 |
+
|
133 |
r = requests.post(f'https://whatsapp.turn.io/v1/messages', data=json.dumps(data), headers=headers)
|
134 |
print("==================")
|
135 |
print("Headers")
|