-
Notifications
You must be signed in to change notification settings - Fork 44
Expand file tree
/
Copy pathreceiveNotification.py
More file actions
117 lines (75 loc) · 3.23 KB
/
receiveNotification.py
File metadata and controls
117 lines (75 loc) · 3.23 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
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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
from datetime import datetime
from json import dumps
from whatsapp_api_client_python import API
greenAPI = API.GreenAPI(
"1101000001", "d75b3a66374942c5b3c019c698abc2067e151558acbd412345"
)
def main():
greenAPI.webhooks.startReceivingNotifications(handler)
def handler(type_webhook: str, body: dict) -> None:
if type_webhook == "incomingMessageReceived":
incoming_message_received(body)
elif type_webhook == "outgoingMessageReceived":
outgoing_message_received(body)
elif type_webhook == "outgoingAPIMessageReceived":
outgoing_api_message_received(body)
elif type_webhook == "outgoingMessageStatus":
outgoing_message_status(body)
elif type_webhook == "stateInstanceChanged":
state_instance_changed(body)
elif type_webhook == "deviceInfo":
device_info(body)
elif type_webhook == "incomingCall":
incoming_call(body)
elif type_webhook == "statusInstanceChanged":
status_instance_changed(body)
def get_notification_time(timestamp: int) -> str:
return str(datetime.fromtimestamp(timestamp))
def incoming_message_received(body: dict) -> None:
timestamp = body["timestamp"]
time = get_notification_time(timestamp)
data = dumps(body, ensure_ascii=False, indent=4)
print(f"New incoming message at {time} with data: {data}", end="\n\n")
def outgoing_message_received(body: dict) -> None:
timestamp = body["timestamp"]
time = get_notification_time(timestamp)
data = dumps(body, ensure_ascii=False, indent=4)
print(f"New outgoing message at {time} with data: {data}", end="\n\n")
def outgoing_api_message_received(body: dict) -> None:
timestamp = body["timestamp"]
time = get_notification_time(timestamp)
data = dumps(body, ensure_ascii=False, indent=4)
print(f"New outgoing API message at {time} with data: {data}", end="\n\n")
def outgoing_message_status(body: dict) -> None:
timestamp = body["timestamp"]
time = get_notification_time(timestamp)
data = dumps(body, ensure_ascii=False, indent=4)
response = (
f"Status of sent message has been updated at {time} with data: {data}"
)
print(response, end="\n\n")
def state_instance_changed(body: dict) -> None:
timestamp = body["timestamp"]
time = get_notification_time(timestamp)
data = dumps(body, ensure_ascii=False, indent=4)
print(f"Current instance state at {time} with data: {data}", end="\n\n")
def device_info(body: dict) -> None:
timestamp = body["timestamp"]
time = get_notification_time(timestamp)
data = dumps(body, ensure_ascii=False, indent=4)
response = (
f"Current device information at {time} with data: {data}"
)
print(response, end="\n\n")
def incoming_call(body: dict) -> None:
timestamp = body["timestamp"]
time = get_notification_time(timestamp)
data = dumps(body, ensure_ascii=False, indent=4)
print(f"New incoming call at {time} with data: {data}", end="\n\n")
def status_instance_changed(body: dict) -> None:
timestamp = body["timestamp"]
time = get_notification_time(timestamp)
data = dumps(body, ensure_ascii=False, indent=4)
print(f"Current instance status at {time} with data: {data}", end="\n\n")
if __name__ == '__main__':
main()