callback.py
35.1 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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Time : 2020-02-09 15:52
# @Author : Lemon
# @File : callback.py
# @Software: PyCharm
import logging
from threading import Thread
from fbchat import ThreadType, Message, \
ShareAttachment, FileAttachment, AudioAttachment, VideoAttachment, ImageAttachment, Sticker, LocationAttachment
from lib import common
from lib.facebook import FacebookClient
from lib.sqlhelper import UserList, Status
from munch import Munch
log = logging.getLogger(__name__)
class CallBack():
def _notify_(self, type_, client, body: dict):
print('【%s】' % type_, body)
def _task_(self, type_, client, taskid: int, code: int, msg: dict = None):
print('【%s】' % type_, code, msg)
def onLoggingIn(self, email, password, cookie):
user_obj = UserList.get(email=email)
if not user_obj:
user_obj = UserList.insert(email=email, password=password, status=Status.LOGGINE, cookie=cookie)
else:
user_obj.set(status=Status.LOGGINE)
return user_obj
def onLoggedIn(self, client: FacebookClient):
client.user_obj.set(fbid=client.uid,
status=Status.ONLINE,
cookie=client.get_cookie())
self._notify_(
type_="account",
client=client,
body={'event': 'onUpdateMyInfo', 'info': client.info()}
)
t = Thread(target=client.listen, name=client.email, args=(True,))
t.setDaemon(True)
t.start()
def onLoggingError(self, email, reason, taskid=0):
u = UserList.get(email=email)
if u: u.set(status=Status.FAILED)
client = Munch(email=email)
self._notify_(
type_="account",
client=client,
body={'event': 'onLoginFailed', 'reason': reason}
)
def onLogout(self, client):
client.user_obj.set(status=Status.OFFLINE)
self._notify_(
type_="account",
client=client,
body={'event': 'onLogout', 'cookie': client.get_cookie()}
)
def onListening(self, client):
self._notify_(
type_="account",
client=client,
body={'cookie': client.get_cookie(), 'event': 'onLoginSuccess'}
)
def onListenError(self, client: FacebookClient, exception=None):
self._notify_(
type_="error",
client=client,
body={'msg': "Got exception while listening {}".format(exception)}
)
return True
def onMessage(
self,
client: FacebookClient,
mid=None,
author_id=None,
message=None,
message_object: Message = None,
thread_id=None,
thread_type=ThreadType.USER,
ts=None,
metadata=None,
msg=None,
):
client.markAsDelivered(thread_id, message_object.uid)
client.markAsRead(thread_id)
body = {
"to": client.uid,
"msgId": mid,
"from": thread_id,
"timeInMillis": ts
}
if thread_type == ThreadType.GROUP:
body['roomSender'] = author_id
if message_object.text:
body['content'] = message_object.text
self._notify_(type_="textMsg", client=client, body=body)
else:
self._fixattachments(message_object, msg)
if message_object.attachments:
msg = message_object.attachments[0]
if isinstance(msg, ShareAttachment):
body.update(common.todict(msg))
self._notify_(type_="linkMsg", client=client, body=body)
elif isinstance(msg, FileAttachment):
body.update(common.todict(msg))
self._notify_(type_="fileMsg", client=client, body=body)
elif isinstance(msg, AudioAttachment):
body.update(common.todict(msg))
self._notify_(type_="voiceMsg", client=client, body=body)
elif isinstance(msg, VideoAttachment):
body.update(common.todict(msg))
self._notify_(type_="videoMsg", client=client, body=body)
elif isinstance(msg, ImageAttachment):
body.update(common.todict(msg))
self._notify_(type_="imageMsg", client=client, body=body)
else:
body.update(common.todict(msg))
self._notify_(type_="unknownMsg", client=client, body=body)
elif message_object.sticker:
body.update(common.todict(message_object.sticker))
self._notify_(type_="stickerMsg", client=client, body=body)
else:
print(message_object)
def _fixattachments(self, message_object, msg):
if msg.get("attachments") and not message_object.attachments:
try:
data = msg.get("attachments")[0]['mercury']['extensible_attachment']['story_attachment']
if data.get("target", {}).get('__typename') == 'User':
message_object.attachments.append(ShareAttachment._from_graphql(data))
except:
pass
def onColorChange(
self,
client: FacebookClient,
mid=None,
author_id=None,
new_color=None,
thread_id=None,
thread_type=ThreadType.USER,
ts=None,
metadata=None,
msg=None,
):
body = {
'actorFbId': msg['messageMetadata']['actorFbId'],
'adminText': msg['messageMetadata']['adminText'],
'type': msg['type'],
'class': msg['class'],
'thread_id': thread_id,
'thread_type': thread_type.name,
}
body.update(msg['untypedData'])
self._notify_(type_="colorChange", client=client, body=body)
def onEmojiChange(
self,
client: FacebookClient,
mid=None,
author_id=None,
new_emoji=None,
thread_id=None,
thread_type=ThreadType.USER,
ts=None,
metadata=None,
msg=None,
):
body = {
'new_emoji': new_emoji,
'actorFbId': msg['messageMetadata']['actorFbId'],
'adminText': msg['messageMetadata']['adminText'],
'type': msg['type'],
'class': msg['class'],
'thread_id': thread_id,
'thread_type': thread_type.name,
}
body.update(msg['untypedData'])
self._notify_(type_="emojiChange", client=client, body=body)
def onTitleChange(
self,
client: FacebookClient,
mid=None,
author_id=None,
new_title=None,
thread_id=None,
thread_type=ThreadType.USER,
ts=None,
metadata=None,
msg=None,
):
body = {
'new_title': new_title,
'actorFbId': msg['messageMetadata']['actorFbId'],
'adminText': msg['messageMetadata']['adminText'],
'type': msg['type'],
'class': msg['class'],
'thread_id': thread_id,
'thread_type': thread_type.name,
}
body.update(msg['untypedData'])
self._notify_(type_="nicknameChange", client=client, body=body)
def onImageChange(
self,
client: FacebookClient,
mid=None,
author_id=None,
new_image=None,
thread_id=None,
thread_type=ThreadType.GROUP,
ts=None,
msg=None,
):
log.info("{} changed thread image in {}".format(author_id, thread_id))
def onNicknameChange(
self,
client: FacebookClient,
mid=None,
author_id=None,
changed_for=None,
new_nickname=None,
thread_id=None,
thread_type=ThreadType.USER,
ts=None,
metadata=None,
msg=None,
):
body = {
'new_nickname': new_nickname,
'actorFbId': msg['messageMetadata']['actorFbId'],
'adminText': msg['messageMetadata']['adminText'],
'type': msg['type'],
'class': msg['class'],
'thread_id': thread_id,
'thread_type': thread_type.name,
}
body.update(msg['untypedData'])
self._notify_(type_="nicknameChange", client=client, body=body)
def onAdminAdded(
self,
client: FacebookClient,
mid=None,
added_id=None,
author_id=None,
thread_id=None,
thread_type=ThreadType.GROUP,
ts=None,
msg=None,
):
log.info("{} added admin: {} in {}".format(author_id, added_id, thread_id))
def onAdminRemoved(
self,
client: FacebookClient,
mid=None,
removed_id=None,
author_id=None,
thread_id=None,
thread_type=ThreadType.GROUP,
ts=None,
msg=None,
):
log.info("{} removed admin: {} in {}".format(author_id, removed_id, thread_id))
def onApprovalModeChange(
self,
client: FacebookClient,
mid=None,
approval_mode=None,
author_id=None,
thread_id=None,
thread_type=ThreadType.GROUP,
ts=None,
msg=None,
):
"""Called when the client is listening, and somebody changes approval mode in a group.
Args:
mid: The action ID
approval_mode: True if approval mode is activated
author_id: The ID of the person who changed approval mode
thread_id: Thread ID that the action was sent to. See :ref:`intro_threads`
ts: A timestamp of the action
msg: A full set of the data received
"""
if approval_mode:
log.info("{} activated approval mode in {}".format(author_id, thread_id))
else:
log.info("{} disabled approval mode in {}".format(author_id, thread_id))
def onMessageSeen(
self,
client: FacebookClient,
seen_by=None,
thread_id=None,
thread_type=ThreadType.USER,
seen_ts=None,
ts=None,
metadata=None,
msg=None,
):
"""Called when the client is listening, and somebody marks a message as seen.
Args:
seen_by: The ID of the person who marked the message as seen
thread_id: Thread ID that the action was sent to. See :ref:`intro_threads`
thread_type (ThreadType): Type of thread that the action was sent to. See :ref:`intro_threads`
seen_ts: A timestamp of when the person saw the message
ts: A timestamp of the action
metadata: Extra metadata about the action
msg: A full set of the data received
"""
log.info(
"Messages seen by {} in {} ({}) at {}s".format(
seen_by, thread_id, thread_type.name, seen_ts / 1000
)
)
def onMessageDelivered(
self,
client: FacebookClient,
msg_ids=None,
delivered_for=None,
thread_id=None,
thread_type=ThreadType.USER,
ts=None,
metadata=None,
msg=None,
):
"""Called when the client is listening, and somebody marks messages as delivered.
Args:
msg_ids: The messages that are marked as delivered
delivered_for: The person that marked the messages as delivered
thread_id: Thread ID that the action was sent to. See :ref:`intro_threads`
thread_type (ThreadType): Type of thread that the action was sent to. See :ref:`intro_threads`
ts: A timestamp of the action
metadata: Extra metadata about the action
msg: A full set of the data received
"""
log.info(
"Messages {} delivered to {} in {} ({}) at {}s".format(
msg_ids, delivered_for, thread_id, thread_type.name, ts / 1000
)
)
def onMarkedSeen(
self, client: FacebookClient, threads=None, seen_ts=None, ts=None, metadata=None, msg=None
):
"""Called when the client is listening, and the client has successfully marked threads as seen.
Args:
threads: The threads that were marked
author_id: The ID of the person who changed the emoji
seen_ts: A timestamp of when the threads were seen
ts: A timestamp of the action
metadata: Extra metadata about the action
msg: A full set of the data received
"""
log.info(
"Marked messages as seen in threads {} at {}s".format(
[(x[0], x[1].name) for x in threads], seen_ts / 1000
)
)
def onMessageUnsent(
self,
client: FacebookClient,
mid=None,
author_id=None,
thread_id=None,
thread_type=None,
ts=None,
msg=None,
):
"""Called when the client is listening, and someone unsends (deletes for everyone) a message.
Args:
mid: ID of the unsent message
author_id: The ID of the person who unsent the message
thread_id: Thread ID that the action was sent to. See :ref:`intro_threads`
thread_type (ThreadType): Type of thread that the action was sent to. See :ref:`intro_threads`
ts: A timestamp of the action
msg: A full set of the data received
"""
log.info(
"{} unsent the message {} in {} ({}) at {}s".format(
author_id, repr(mid), thread_id, thread_type.name, ts / 1000
)
)
def onPeopleAdded(
self,
client: FacebookClient,
mid=None,
added_ids=None,
author_id=None,
thread_id=None,
ts=None,
msg=None,
):
"""Called when the client is listening, and somebody adds people to a group thread.
Args:
mid: The action ID
added_ids: The IDs of the people who got added
author_id: The ID of the person who added the people
thread_id: Thread ID that the action was sent to. See :ref:`intro_threads`
ts: A timestamp of the action
msg: A full set of the data received
"""
log.info(
"{} added: {} in {}".format(author_id, ", ".join(added_ids), thread_id)
)
def onPersonRemoved(
self,
client: FacebookClient,
mid=None,
removed_id=None,
author_id=None,
thread_id=None,
ts=None,
msg=None,
):
"""Called when the client is listening, and somebody removes a person from a group thread.
Args:
mid: The action ID
removed_id: The ID of the person who got removed
author_id: The ID of the person who removed the person
thread_id: Thread ID that the action was sent to. See :ref:`intro_threads`
ts: A timestamp of the action
msg: A full set of the data received
"""
log.info("{} removed: {} in {}".format(author_id, removed_id, thread_id))
def onFriendRequest(self, client: FacebookClient, from_id=None, msg=None):
"""Called when the client is listening, and somebody sends a friend request.
Args:
from_id: The ID of the person that sent the request
msg: A full set of the data received
"""
from_id = str(from_id)
log.info("Friend request from {}".format(from_id))
try:
info = client._fetchInfo(from_id)[from_id]
info.pop("type")
except:
info = {"id": from_id}
self._notify_('friendRequest', client, body=info)
def _onSeen(self, client: FacebookClient, locations=None, ts=None, msg=None):
"""
Todo:
Document this, and make it public
Args:
locations: ---
ts: A timestamp of the action
msg: A full set of the data received
"""
def onInbox(self, client: FacebookClient, unseen=None, unread=None, recent_unread=None, msg=None):
"""
Todo:
Documenting this
Args:
unseen: --
unread: --
recent_unread: --
msg: A full set of the data received
"""
log.info("Inbox event: {}, {}, {}".format(unseen, unread, recent_unread))
def onTyping(
self, client: FacebookClient, author_id=None, status=None, thread_id=None, thread_type=None,
msg=None
):
"""Called when the client is listening, and somebody starts or stops typing into a chat.
Args:
author_id: The ID of the person who sent the action
status (TypingStatus): The typing status
thread_id: Thread ID that the action was sent to. See :ref:`intro_threads`
thread_type (ThreadType): Type of thread that the action was sent to. See :ref:`intro_threads`
msg: A full set of the data received
"""
print("onTyping")
def onGamePlayed(
self,
client: FacebookClient,
mid=None,
author_id=None,
game_id=None,
game_name=None,
score=None,
leaderboard=None,
thread_id=None,
thread_type=None,
ts=None,
metadata=None,
msg=None,
):
"""Called when the client is listening, and somebody plays a game.
Args:
mid: The action ID
author_id: The ID of the person who played the game
game_id: The ID of the game
game_name: Name of the game
score: Score obtained in the game
leaderboard: Actual leader board of the game in the thread
thread_id: Thread ID that the action was sent to. See :ref:`intro_threads`
thread_type (ThreadType): Type of thread that the action was sent to. See :ref:`intro_threads`
ts: A timestamp of the action
metadata: Extra metadata about the action
msg: A full set of the data received
"""
log.info(
'{} played "{}" in {} ({})'.format(
author_id, game_name, thread_id, thread_type.name
)
)
def onReactionAdded(
self,
client: FacebookClient,
mid=None,
reaction=None,
author_id=None,
thread_id=None,
thread_type=None,
ts=None,
msg=None,
):
"""Called when the client is listening, and somebody reacts to a message.
Args:
mid: Message ID, that user reacted to
reaction (MessageReaction): Reaction
add_reaction: Whether user added or removed reaction
author_id: The ID of the person who reacted to the message
thread_id: Thread ID that the action was sent to. See :ref:`intro_threads`
thread_type (ThreadType): Type of thread that the action was sent to. See :ref:`intro_threads`
ts: A timestamp of the action
msg: A full set of the data received
"""
body = {
'thread_id': thread_id,
'thread_type': thread_type.name,
'author_id': author_id,
'mid': mid,
'action': 'add',
'reaction': reaction.value
}
self._notify_('reactionMsg', client, body=body)
def onReactionRemoved(
self,
client: FacebookClient,
mid=None,
author_id=None,
thread_id=None,
thread_type=None,
ts=None,
msg=None,
):
"""Called when the client is listening, and somebody removes reaction from a message.
Args:
mid: Message ID, that user reacted to
author_id: The ID of the person who removed reaction
thread_id: Thread ID that the action was sent to. See :ref:`intro_threads`
thread_type (ThreadType): Type of thread that the action was sent to. See :ref:`intro_threads`
ts: A timestamp of the action
msg: A full set of the data received
"""
body = {
'thread_id': thread_id,
'thread_type': thread_type.name,
'author_id': author_id,
'mid': mid,
'action': 'remove',
}
self._notify_('reactionMsg', client, body=body)
def onBlock(
self, client: FacebookClient, author_id=None, thread_id=None, thread_type=None, ts=None, msg=None
):
"""Called when the client is listening, and somebody blocks client.
Args:
author_id: The ID of the person who blocked
thread_id: Thread ID that the action was sent to. See :ref:`intro_threads`
thread_type (ThreadType): Type of thread that the action was sent to. See :ref:`intro_threads`
ts: A timestamp of the action
msg: A full set of the data received
"""
log.info(
"{} blocked {} ({}) thread".format(author_id, thread_id, thread_type.name)
)
def onUnblock(
self, client: FacebookClient, author_id=None, thread_id=None, thread_type=None, ts=None, msg=None
):
"""Called when the client is listening, and somebody blocks client.
Args:
author_id: The ID of the person who unblocked
thread_id: Thread ID that the action was sent to. See :ref:`intro_threads`
thread_type (ThreadType): Type of thread that the action was sent to. See :ref:`intro_threads`
ts: A timestamp of the action
msg: A full set of the data received
"""
log.info(
"{} unblocked {} ({}) thread".format(author_id, thread_id, thread_type.name)
)
def onLiveLocation(
self,
client: FacebookClient,
mid=None,
location=None,
author_id=None,
thread_id=None,
thread_type=None,
ts=None,
msg=None,
):
"""Called when the client is listening and somebody sends live location info.
Args:
mid: The action ID
location (LiveLocationAttachment): Sent location info
author_id: The ID of the person who sent location info
thread_id: Thread ID that the action was sent to. See :ref:`intro_threads`
thread_type (ThreadType): Type of thread that the action was sent to. See :ref:`intro_threads`
ts: A timestamp of the action
msg: A full set of the data received
"""
log.info(
"{} sent live location info in {} ({}) with latitude {} and longitude {}".format(
author_id, thread_id, thread_type, location.latitude, location.longitude
)
)
def onCallStarted(
self,
client: FacebookClient,
mid=None,
caller_id=None,
is_video_call=None,
thread_id=None,
thread_type=None,
ts=None,
metadata=None,
msg=None,
):
"""Called when the client is listening, and somebody starts a call in a group.
Todo:
Make this work with private calls.
Args:
mid: The action ID
caller_id: The ID of the person who started the call
is_video_call: True if it's video call
thread_id: Thread ID that the action was sent to. See :ref:`intro_threads`
thread_type (ThreadType): Type of thread that the action was sent to. See :ref:`intro_threads`
ts: A timestamp of the action
metadata: Extra metadata about the action
msg: A full set of the data received
"""
log.info(
"{} started call in {} ({})".format(caller_id, thread_id, thread_type.name)
)
def onCallEnded(
self,
client: FacebookClient,
mid=None,
caller_id=None,
is_video_call=None,
call_duration=None,
thread_id=None,
thread_type=None,
ts=None,
metadata=None,
msg=None,
):
"""Called when the client is listening, and somebody ends a call in a group.
Todo:
Make this work with private calls.
Args:
mid: The action ID
caller_id: The ID of the person who ended the call
is_video_call: True if it was video call
call_duration: Call duration in seconds
thread_id: Thread ID that the action was sent to. See :ref:`intro_threads`
thread_type (ThreadType): Type of thread that the action was sent to. See :ref:`intro_threads`
ts: A timestamp of the action
metadata: Extra metadata about the action
msg: A full set of the data received
"""
log.info(
"{} ended call in {} ({})".format(caller_id, thread_id, thread_type.name)
)
def onUserJoinedCall(
self,
client: FacebookClient,
mid=None,
joined_id=None,
is_video_call=None,
thread_id=None,
thread_type=None,
ts=None,
metadata=None,
msg=None,
):
"""Called when the client is listening, and somebody joins a group call.
Args:
mid: The action ID
joined_id: The ID of the person who joined the call
is_video_call: True if it's video call
thread_id: Thread ID that the action was sent to. See :ref:`intro_threads`
thread_type (ThreadType): Type of thread that the action was sent to. See :ref:`intro_threads`
ts: A timestamp of the action
metadata: Extra metadata about the action
msg: A full set of the data received
"""
log.info(
"{} joined call in {} ({})".format(joined_id, thread_id, thread_type.name)
)
def onPollCreated(
self,
client: FacebookClient,
mid=None,
poll=None,
author_id=None,
thread_id=None,
thread_type=None,
ts=None,
metadata=None,
msg=None,
):
"""Called when the client is listening, and somebody creates a group poll.
Args:
mid: The action ID
poll (Poll): Created poll
author_id: The ID of the person who created the poll
thread_id: Thread ID that the action was sent to. See :ref:`intro_threads`
thread_type (ThreadType): Type of thread that the action was sent to. See :ref:`intro_threads`
ts: A timestamp of the action
metadata: Extra metadata about the action
msg: A full set of the data received
"""
log.info(
"{} created poll {} in {} ({})".format(
author_id, poll, thread_id, thread_type.name
)
)
def onPollVoted(
self,
client: FacebookClient,
mid=None,
poll=None,
added_options=None,
removed_options=None,
author_id=None,
thread_id=None,
thread_type=None,
ts=None,
metadata=None,
msg=None,
):
"""Called when the client is listening, and somebody votes in a group poll.
Args:
mid: The action ID
poll (Poll): Poll, that user voted in
author_id: The ID of the person who voted in the poll
thread_id: Thread ID that the action was sent to. See :ref:`intro_threads`
thread_type (ThreadType): Type of thread that the action was sent to. See :ref:`intro_threads`
ts: A timestamp of the action
metadata: Extra metadata about the action
msg: A full set of the data received
"""
log.info(
"{} voted in poll {} in {} ({})".format(
author_id, poll, thread_id, thread_type.name
)
)
def onPlanCreated(
self,
client: FacebookClient,
mid=None,
plan=None,
author_id=None,
thread_id=None,
thread_type=None,
ts=None,
metadata=None,
msg=None,
):
"""Called when the client is listening, and somebody creates a plan.
Args:
mid: The action ID
plan (Plan): Created plan
author_id: The ID of the person who created the plan
thread_id: Thread ID that the action was sent to. See :ref:`intro_threads`
thread_type (ThreadType): Type of thread that the action was sent to. See :ref:`intro_threads`
ts: A timestamp of the action
metadata: Extra metadata about the action
msg: A full set of the data received
"""
log.info(
"{} created plan {} in {} ({})".format(
author_id, plan, thread_id, thread_type.name
)
)
def onPlanEnded(
self,
client: FacebookClient,
mid=None,
plan=None,
thread_id=None,
thread_type=None,
ts=None,
metadata=None,
msg=None,
):
"""Called when the client is listening, and a plan ends.
Args:
mid: The action ID
plan (Plan): Ended plan
thread_id: Thread ID that the action was sent to. See :ref:`intro_threads`
thread_type (ThreadType): Type of thread that the action was sent to. See :ref:`intro_threads`
ts: A timestamp of the action
metadata: Extra metadata about the action
msg: A full set of the data received
"""
log.info(
"Plan {} has ended in {} ({})".format(plan, thread_id, thread_type.name)
)
def onPlanEdited(
self,
client: FacebookClient,
mid=None,
plan=None,
author_id=None,
thread_id=None,
thread_type=None,
ts=None,
metadata=None,
msg=None,
):
"""Called when the client is listening, and somebody edits a plan.
Args:
mid: The action ID
plan (Plan): Edited plan
author_id: The ID of the person who edited the plan
thread_id: Thread ID that the action was sent to. See :ref:`intro_threads`
thread_type (ThreadType): Type of thread that the action was sent to. See :ref:`intro_threads`
ts: A timestamp of the action
metadata: Extra metadata about the action
msg: A full set of the data received
"""
log.info(
"{} edited plan {} in {} ({})".format(
author_id, plan, thread_id, thread_type.name
)
)
def onPlanDeleted(
self,
client: FacebookClient,
mid=None,
plan=None,
author_id=None,
thread_id=None,
thread_type=None,
ts=None,
metadata=None,
msg=None,
):
"""Called when the client is listening, and somebody deletes a plan.
Args:
mid: The action ID
plan (Plan): Deleted plan
author_id: The ID of the person who deleted the plan
thread_id: Thread ID that the action was sent to. See :ref:`intro_threads`
thread_type (ThreadType): Type of thread that the action was sent to. See :ref:`intro_threads`
ts: A timestamp of the action
metadata: Extra metadata about the action
msg: A full set of the data received
"""
log.info(
"{} deleted plan {} in {} ({})".format(
author_id, plan, thread_id, thread_type.name
)
)
def onPlanParticipation(
self,
client: FacebookClient,
mid=None,
plan=None,
take_part=None,
author_id=None,
thread_id=None,
thread_type=None,
ts=None,
metadata=None,
msg=None,
):
"""Called when the client is listening, and somebody takes part in a plan or not.
Args:
mid: The action ID
plan (Plan): Plan
take_part (bool): Whether the person takes part in the plan or not
author_id: The ID of the person who will participate in the plan or not
thread_id: Thread ID that the action was sent to. See :ref:`intro_threads`
thread_type (ThreadType): Type of thread that the action was sent to. See :ref:`intro_threads`
ts: A timestamp of the action
metadata: Extra metadata about the action
msg: A full set of the data received
"""
if take_part:
log.info(
"{} will take part in {} in {} ({})".format(
author_id, plan, thread_id, thread_type.name
)
)
else:
log.info(
"{} won't take part in {} in {} ({})".format(
author_id, plan, thread_id, thread_type.name
)
)
def onQprimer(self, client: FacebookClient, ts=None, msg=None):
"""Called when the client just started listening.
Args:
ts: A timestamp of the action
msg: A full set of the data received
"""
pass
def onChatTimestamp(self, client: FacebookClient, buddylist=None, msg=None):
"""Called when the client receives chat online presence update.
Args:
buddylist: A list of dictionaries with friend id and last seen timestamp
msg: A full set of the data received
"""
log.debug("Chat Timestamps received: {}".format(buddylist))
def onBuddylistOverlay(self, client: FacebookClient, statuses=None, msg=None):
"""Called when the client is listening and client receives information about friend active status.
Args:
statuses (dict): Dictionary with user IDs as keys and :class:`ActiveStatus` as values
msg: A full set of the data received
"""
def onUnknownMesssageType(self, client: FacebookClient, msg=None):
"""Called when the client is listening, and some unknown data was received.
Args:
msg: A full set of the data received
"""
log.debug("Unknown message received: {}".format(msg))
def onMessageError(self, client: FacebookClient, exception=None, msg=None):
"""Called when an error was encountered while parsing received data.
Args:
exception: The exception that was encountered
msg: A full set of the data received
"""
log.exception("Exception in parsing of {}".format(msg))