forked from stypr/clubhouse-py
-
Notifications
You must be signed in to change notification settings - Fork 0
/
clubhouse.py
1456 lines (1330 loc) · 50.4 KB
/
clubhouse.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
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
#!/usr/bin/python -u
#-*- coding: utf-8 -*-
# pylint: disable=line-too-long,too-many-arguments,too-many-lines
# pylint: disable=no-self-argument,not-callable
"""
clubhouse.py
Developed for education purposes only.
Please make sure to know what you're trying to do!
Sending an odd API request could result in a permanent ban on your account.
"""
import uuid
import random
import secrets
import functools
import requests
class Clubhouse:
"""
Clubhouse Class
Decorators:
@require_authentication:
- this means that the endpoint requires authentication to access.
@unstable_endpoint
- This means that the endpoint is never tested.
- Likely to be endpoints that were taken from a static analysis
"""
# App/API Information
API_URL = "https://www.clubhouseapi.com/api"
API_BUILD_ID = "304"
API_BUILD_VERSION = "0.1.28"
API_UA = f"clubhouse/{API_BUILD_ID} (iPhone; iOS 13.5.1; Scale/3.00)"
# Some useful information for commmunication
PUBNUB_PUB_KEY = "pub-c-6878d382-5ae6-4494-9099-f930f938868b"
PUBNUB_SUB_KEY = "sub-c-a4abea84-9ca3-11ea-8e71-f2b83ac9263d"
TWITTER_ID = "NyJhARWVYU1X3qJZtC2154xSI"
TWITTER_SECRET = "ylFImLBFaOE362uwr4jut8S8gXGWh93S1TUKbkfh7jDIPse02o"
AGORA_KEY = "938de3e8055e42b281bb8c6f69c21f78"
SENTRY_KEY = "5374a416cd2d4009a781b49d1bd9ef44@o325556.ingest.sentry.io/5245095"
INSTABUG_KEY = "4e53155da9b00728caa5249f2e35d6b3"
AMPLITUDE_KEY = "9098a21a950e7cb0933fb5b30affe5be"
# Useful header information
HEADERS = {
"CH-Languages": "en-JP,ja-JP",
"CH-Locale": "en_JP",
"Accept": "application/json",
"Accept-Language": "en-JP;q=1, ja-JP;q=0.9",
"Accept-Encoding": "gzip, deflate",
"CH-AppBuild": f"{API_BUILD_ID}",
"CH-AppVersion": f"{API_BUILD_VERSION}",
"User-Agent": f"{API_UA}",
"Connection": "close",
"Content-Type": "application/json; charset=utf-8",
"Cookie": f"__cfduid={secrets.token_hex(21)}{random.randint(1, 9)}"
}
def require_authentication(func):
""" Simple decorator to check for the authentication """
@functools.wraps(func)
def wrap(self, *args, **kwargs):
if not (self.HEADERS.get("CH-UserID") and
self.HEADERS.get("CH-DeviceId") and
self.HEADERS.get("Authorization")):
raise Exception('Not Authenticated')
return func(self, *args, **kwargs)
return wrap
def unstable_endpoint(func):
""" Simple decorator to warn that this endpoint is never tested at all. """
@functools.wraps(func)
def wrap(self, *args, **kwargs):
print("[!] This endpoint is NEVER TESTED and MAY BE UNSTABLE. BE CAREFUL!")
return func(self, *args, **kwargs)
return wrap
def __init__(self, user_id='', user_token='', user_device=''):
""" (Clubhouse, str, str, str) -> NoneType
Set authenticated information
"""
self.HEADERS['CH-UserID'] = user_id if user_id else "(null)"
if user_token:
self.HEADERS['Authorization'] = f"Token {user_token}"
self.HEADERS['CH-DeviceId'] = user_device.upper() if user_device else str(uuid.uuid4()).upper()
def __str__(self):
""" (Clubhouse) -> str
Get information about the given class.
>>> clubhouse = Clubhouse()
>>> str(clubhouse)
Clubhouse(user_id=(null), user_token=None, user_device=31525f52-6b67-40de-83c0-8f9fe0f6f409)
"""
return "Clubhouse(user_Id={}, user_token={}, user_device={}".format(
self.HEADERS.get('CH-UserID'),
self.HEADERS.get('Authorization'),
self.HEADERS.get('CH-DeviceId')
)
def start_phone_number_auth(self, phone_number):
""" (Clubhouse, str) -> dict
Begin phone number authentication.
Some examples for the phone number.
>>> clubhouse = Clubhouse()
>>> clubhouse.start_phone_number_auth("+821012341337")
...
>>> clubhouse.start_phone_number_auth("+818013371221")
...
"""
if self.HEADERS.get("Authorization"):
raise Exception('Already Authenticatied')
data = {
"phone_number": phone_number
}
req = requests.post(f"{self.API_URL}/start_phone_number_auth", headers=self.HEADERS, json=data)
return req.json()
@unstable_endpoint
def call_phone_number_auth(self, phone_number):
""" (Clubhouse, str) -> dict
Call the person and send verification message.
"""
if self.HEADERS.get("Authorization"):
raise Exception('Already Authenticatied')
data = {
"phone_number": phone_number
}
req = requests.post(f"{self.API_URL}/call_phone_number_auth", headers=self.HEADERS, json=data)
return req.json()
@unstable_endpoint
def resend_phone_number_auth(self, phone_number):
""" (Clubhouse, str) -> dict
Resend the verification message
"""
if self.HEADERS.get("Authorization"):
raise Exception('Already Authenticatied')
data = {
"phone_number": phone_number
}
req = requests.post(f"{self.API_URL}/resend_phone_number_auth", headers=self.HEADERS, json=data)
return req.json()
def complete_phone_number_auth(self, phone_number, verification_code):
""" (Clubhouse, str, str) -> dict
Complete phone number authentication.
This should return `auth_token`, `access_token`, `refresh_token`, is_waitlisted, ...
Please note that output may be different depending on the status of the authenticated user
"""
if self.HEADERS.get("Authorization"):
raise Exception('Already Authenticatied')
data = {
"phone_number": phone_number,
"verification_code": verification_code
}
req = requests.post(f"{self.API_URL}/complete_phone_number_auth", headers=self.HEADERS, json=data)
return req.json()
def check_for_update(self, is_testflight=False):
""" (Clubhouse, bool) -> dict
Check for app updates.
>>> clubhouse = Clubhouse()
>>> clubhouse.check_for_update(False)
{'has_update': False, 'success': True}
"""
query = f"is_testflight={int(is_testflight)}"
req = requests.get(f"{self.API_URL}/check_for_update?{query}", headers=self.HEADERS)
return req.json()
@require_authentication
def get_release_notes(self):
""" (Clubhouse) -> dict
Get release notes.
"""
req = requests.post(f"{self.API_URL}/get_release_notes", headers=self.HEADERS)
return req.json()
@require_authentication
def check_waitlist_status(self):
""" (Clubhouse) -> dict
Check whether you're still on a waitlist or not.
"""
req = requests.post(f"{self.API_URL}/check_waitlist_status", headers=self.HEADERS)
return req.json()
@require_authentication
def add_email(self, email):
""" (Clubhouse, str) -> dict
Request for email verification.
You only need to do this once.
"""
data = {
"email": email
}
req = requests.post(f"{self.API_URL}/add_email", headers=self.HEADERS, json=data)
return req.json()
@require_authentication
def update_photo(self, photo_filename):
""" (Clubhouse, str) -> dict
Update photo. Please make sure to upload a JPG format.
"""
files = {
"file": ("image.jpg", open(photo_filename, "rb"), "image/jpeg"),
}
tmp = self.HEADERS['Content-Type']
self.HEADERS.pop("Content-Type")
req = requests.post(f"{self.API_URL}/update_photo", headers=self.HEADERS, files=files)
self.HEADERS['Content-Type'] = tmp
return req.json()
@require_authentication
def follow(self, user_id, user_ids=None, source=4, source_topic_id=None):
""" (Clubhouse, int, list, int, int) -> dict
Follow a user.
Different value for `source` may require different parameters to be set
"""
data = {
"source_topic_id": source_topic_id,
"user_ids": user_ids,
"user_id": int(user_id),
"source": source
}
req = requests.post(f"{self.API_URL}/follow", headers=self.HEADERS, json=data)
return req.json()
@require_authentication
def unfollow(self, user_id):
""" (Clubhouse, int) -> dict
Unfollow a user.
"""
data = {
"user_id": int(user_id)
}
req = requests.post(f"{self.API_URL}/unfollow", headers=self.HEADERS, json=data)
return req.json()
@require_authentication
def block(self, user_id):
""" (Clubhouse, int) -> dict
Block a user.
"""
data = {
"user_id": int(user_id)
}
req = requests.post(f"{self.API_URL}/block", headers=self.HEADERS, json=data)
return req.json()
@require_authentication
def unblock(self, user_id):
""" (Clubhouse, int) -> dict
Unfollow a user.
"""
data = {
"user_id": int(user_id)
}
req = requests.post(f"{self.API_URL}/unblock", headers=self.HEADERS, json=data)
return req.json()
@require_authentication
def follow_multiple(self, user_ids, user_id=None, source=7, source_topic_id=None):
""" (Clubhouse, list, int, int, int) -> dict
Follow multiple users at once.
Different value for `source` may require different parameters to be set
"""
data = {
"source_topic_id": source_topic_id,
"user_ids": user_ids,
"user_id": user_id,
"source": source
}
req = requests.post(f"{self.API_URL}/follow_multiple", headers=self.HEADERS, json=data)
return req.json()
@require_authentication
def follow_club(self, club_id, source_topic_id=None):
""" (Clubhouse, int, int) -> dict
Follow a club
"""
data = {
"club_id": int(club_id),
"source_topic_id": source_topic_id
}
req = requests.post(f"{self.API_URL}/follow_club", headers=self.HEADERS, json=data)
return req.json()
@require_authentication
def unfollow_club(self, club_id, source_topic_id=None):
""" (Clubhouse, int, int) -> dict
Unfollow a club
"""
data = {
"club_id": int(club_id),
"source_topic_id": source_topic_id
}
req = requests.post(f"{self.API_URL}/unfollow_club", headers=self.HEADERS, json=data)
return req.json()
@require_authentication
def update_follow_notifications(self, user_id, notification_type=2):
""" (Clubhouse, str, int) -> dict
Update notification frequency for the given user.
1 = Always notify, 2 = Sometimes, 3 = Never
"""
data = {
"user_id": int(user_id),
"notification_type": int(notification_type)
}
req = requests.post(f"{self.API_URL}/update_follow_notifications", headers=self.HEADERS, json=data)
return req.json()
@require_authentication
def get_suggested_follows_similar(self, user_id):
""" (Clubhouse, int) -> dict
Get similar users based on the given user.
"""
data = {
"user_id": int(user_id),
}
req = requests.post(f"{self.API_URL}/get_suggested_follows_similar", headers=self.HEADERS, json=data)
return req.json()
@require_authentication
def get_suggested_follows_friends_only(self, club_id=None, upload_contacts=True, contacts=()):
""" (Clubhouse, int, int, list of dict) -> dict
Get users based on the phone number.
Only seems to be used upon signup.
"""
data = {
"club_id": club_id,
"upload_contacts": upload_contacts,
"contacts": contacts
}
req = requests.post(f"{self.API_URL}/get_suggested_follows_friends_only", headers=self.HEADERS, json=data)
return req.json()
@require_authentication
def get_suggested_follows_all(self, in_onboarding=True, page_size=50, page=1):
""" (Clubhouse, bool, int, int) -> dict
Get all suggested follows.
"""
query = "in_onboarding={}&page_size={}&page={}".format(
"true" if in_onboarding else "false",
page_size,
page
)
req = requests.get(f"{self.API_URL}/get_suggested_follows_all?{query}", headers=self.HEADERS)
return req.json()
@require_authentication
def ignore_suggested_follow(self, user_id):
""" (Clubhouse, str) -> dict
Remove user_id from the suggested follow list.
"""
data = {
"user_id": int(user_id)
}
req = requests.post(f"{self.API_URL}/user_id", headers=self.HEADERS, json=data)
return req.json()
@require_authentication
def get_event(self, event_id=None, user_ids=None, club_id=None, is_member_only=False, event_hashid=None, description=None, time_start_epoch=None, name=None):
""" (Clubhouse, int, list, int, bool, int, str, int, str) -> dict
Get details about the event
"""
data = {
"user_ids": user_ids,
"club_id": club_id,
"is_member_only": is_member_only,
"event_id": int(event_id),
"event_hashid": event_hashid,
"description": description,
"time_start_epoch": time_start_epoch,
"name": name
}
req = requests.post(f"{self.API_URL}/get_event", headers=self.HEADERS, json=data)
return req.json()
@require_authentication
def create_event(self, name, time_start_epoch, description, event_id=None, user_ids=(), club_id=None, is_member_only=False, event_hashid=None):
""" (Clubhouse, str, int, str, int, list, int, bool, int) -> dict
Create a new event
"""
data = {
"user_ids": user_ids,
"club_id": club_id,
"is_member_only": is_member_only,
"event_id": event_id,
"event_hashid": event_hashid,
"description": description,
"time_start_epoch": time_start_epoch,
"name": name
}
req = requests.post(f"{self.API_URL}/edit_event", headers=self.HEADERS, json=data)
return req.json()
@require_authentication
def edit_event(self, name, time_start_epoch, description, event_id=None, user_ids=(), club_id=None, is_member_only=False, event_hashid=None):
""" (Clubhouse, str, int, str, int, list, int, bool, int) -> dict
Edit an event.
"""
data = {
"user_ids": user_ids,
"club_id": club_id,
"is_member_only": is_member_only,
"event_id": event_id,
"event_hashid": event_hashid,
"description": description,
"time_start_epoch": time_start_epoch,
"name": name
}
req = requests.post(f"{self.API_URL}/edit_event", headers=self.HEADERS, json=data)
return req.json()
@require_authentication
def delete_event(self, event_id, user_ids=None, club_id=None, is_member_only=False, event_hashid=None, description=None, time_start_epoch=None, name=None):
""" (Clubhouse, str, list, int, bool, int, str, int, str) -> dict
Delete event.
"""
data = {
"user_ids": user_ids,
"club_id": club_id,
"is_member_only": is_member_only,
"event_id": event_id,
"event_hashid": event_hashid,
"description": description,
"time_start_epoch": time_start_epoch,
"name": name
}
req = requests.post(f"{self.API_URL}/delete_event", headers=self.HEADERS, json=data)
return req.json()
@require_authentication
def get_events(self, is_filtered=True, page_size=25, page=1):
""" (Clubhouse, bool, int, int) -> dict
Get list of upcoming events with details.
"""
_is_filtered = "true" if is_filtered else "false"
query = "is_filtered={}&page_size={}&page={}".format(
"true" if is_filtered else "false",
page_size,
page
)
req = requests.get(f"{self.API_URL}/get_events?{query}", headers=self.HEADERS)
return req.json()
@require_authentication
def get_club(self, club_id, source_topic_id=None):
""" (Clubhouse, int, int) -> dict
Get the information about the given club_id.
"""
data = {
"club_id": int(club_id),
"source_topic_id": source_topic_id
}
req = requests.post(f"{self.API_URL}/get_club", headers=self.HEADERS, json=data)
return req.json()
@require_authentication
def get_club_members(self, club_id, return_followers=False, return_members=True, page_size=50, page=1):
""" (Clubhouse, int, bool, bool, int, int) -> dict
Get list of members on the given club_id.
"""
query = "club_id={}&return_followers={}&return_members={}&page_size={}&page={}".format(
club_id,
int(return_followers),
int(return_members),
page_size,
page
)
req = requests.get(f"{self.API_URL}/get_club_members?{query}", headers=self.HEADERS)
return req.json()
@require_authentication
def get_settings(self):
""" (Clubhouse) -> dict
Receive user's settings.
"""
req = requests.get(f"{self.API_URL}/get_settings", headers=self.HEADERS)
return req.json()
@require_authentication
def get_welcome_channel(self):
""" (Clubhouse) -> dict
Seems to be called upon sign up. Does not seem to return much data.
"""
req = requests.get(f"{self.API_URL}/get_welcome_channel", headers=self.HEADERS)
return req.json()
@require_authentication
def hide_channel(self, channel, hide=True):
""" (Clubhouse, str, bool) -> dict
Hide/unhide the channel from the channel list.
"""
# Join channel
data = {
"channel": channel,
"hide": hide
}
req = requests.post(f"{self.API_URL}/hide_channel", headers=self.HEADERS, json=data)
return req.json()
@require_authentication
def join_channel(self, channel, attribution_source="feed"):
""" (Clubhouse, str, str) -> dict
Join the given channel
"""
# Join channel
data = {
"channel": channel,
"attribution_source": attribution_source,
"attribution_details": "eyJpc19leHBsb3JlIjpmYWxzZSwicmFuayI6MX0=",
}
req = requests.post(f"{self.API_URL}/join_channel", headers=self.HEADERS, json=data)
return req.json()
@require_authentication
def leave_channel(self, channel):
""" (Clubhouse, str) -> dict
Leave the given channel
"""
data = {
"channel": channel,
"channel_id": None
}
req = requests.post(f"{self.API_URL}/leave_channel", headers=self.HEADERS, json=data)
return req.json()
@require_authentication
def make_channel_public(self, channel, channel_id=None):
""" (Clubhouse, str, int) -> dict
Make the current channel open to public.
Everyone can join the channel.
"""
data = {
"channel": channel,
"channel_id": channel_id
}
req = requests.post(f"{self.API_URL}/make_channel_public", headers=self.HEADERS, json=data)
return req.json()
@require_authentication
def make_channel_social(self, channel, channel_id=None):
""" (Clubhouse, str, int) -> dict
Make the current channel open to public.
Only people who user follows can join the channel.
"""
data = {
"channel": channel,
"channel_id": channel_id
}
req = requests.post(f"{self.API_URL}/make_channel_social", headers=self.HEADERS, json=data)
return req.json()
@require_authentication
def end_channel(self, channel, channel_id=None):
""" (Clubhouse, str, int) -> dict
Kick everyone and close the channel. Requires moderator privilege.
"""
data = {
"channel": channel,
"channel_id": channel_id
}
req = requests.post(f"{self.API_URL}/end_channel", headers=self.HEADERS, json=data)
return req.json()
@require_authentication
def make_moderator(self, channel, user_id):
""" (Clubhouse, str, int) -> dict
Make the given user moderator. Requires moderator privilege.
"""
data = {
"channel": channel,
"user_id": int(user_id)
}
req = requests.post(f"{self.API_URL}/make_moderator", headers=self.HEADERS, json=data)
return req.json()
@require_authentication
def block_from_channel(self, channel, user_id):
""" (Clubhouse, str, int) -> dict
Remove the user from the channel. The user will not be able to re-join.
"""
data = {
"channel": channel,
"user_id": int(user_id)
}
req = requests.post(f"{self.API_URL}/block_from_channel", headers=self.HEADERS, json=data)
return req.json()
@require_authentication
def get_profile(self, user_id):
""" (Clubhouse, str) -> dict
Lookup someone else's profile. It is OK to one's own profile with this method.
"""
data = {
"user_id": int(user_id)
}
req = requests.post(f"{self.API_URL}/get_profile", headers=self.HEADERS, json=data)
return req.json()
@require_authentication
def me(self, return_blocked_ids=False, timezone_identifier="Asia/Tokyo", return_following_ids=False):
""" (Clubhouse, bool, str, bool) -> dict
Get my information
"""
data = {
"return_blocked_ids": return_blocked_ids,
"timezone_identifier": timezone_identifier,
"return_following_ids": return_following_ids
}
req = requests.post(f"{self.API_URL}/me", headers=self.HEADERS, json=data)
return req.json()
@require_authentication
def get_following(self, user_id, page_size=50, page=1):
""" (Clubhouse, str, int, int) -> dict
Get following users type2
"""
query = "user_id={}&page_size={}&page={}".format(
user_id,
page_size,
page
)
req = requests.get(f"{self.API_URL}/get_following?{query}", headers=self.HEADERS)
return req.json()
@require_authentication
def get_followers(self, user_id, page_size=50, page=1):
""" (Clubhouse, str, int, int) -> dict
Get followers of the given user_id.
"""
query = "user_id={}&page_size={}&page={}".format(
user_id,
page_size,
page
)
req = requests.get(f"{self.API_URL}/get_followers?{query}", headers=self.HEADERS)
return req.json()
@require_authentication
def get_mutual_follows(self, user_id, page_size=50, page=1):
""" (Clubhouse, str, int, int) -> dict
Get mutual followers between the current user and the given user_id.
"""
query = "user_id={}&page_size={}&page={}".format(
user_id,
page_size,
page
)
req = requests.get(f"{self.API_URL}/get_mutual_follows?{query}", headers=self.HEADERS)
return req.json()
@require_authentication
def get_all_topics(self):
""" (Clubhouse) -> dict
Get list of topics, based on the server's channel selection algorithm
"""
req = requests.get(f"{self.API_URL}/get_all_topics", headers=self.HEADERS)
return req.json()
@require_authentication
def get_channels(self):
""" (Clubhouse) -> dict
Get list of channels, based on the server's channel selection algorithm
"""
req = requests.get(f"{self.API_URL}/get_channels", headers=self.HEADERS)
return req.json()
@require_authentication
def get_channel(self, channel, channel_id=None):
""" (Clubhouse, str, int) -> dict
Get information of the given channel
"""
data = {
"channel": channel,
"channel_id": channel_id
}
req = requests.post(f"{self.API_URL}/get_channel", headers=self.HEADERS, json=data)
return req.json()
@require_authentication
def active_ping(self, channel):
""" (Clubhouse, str) -> dict
Keeping the user active while being in a chatroom
"""
data = {
"channel": channel,
"chanel_id": None
}
req = requests.post(f"{self.API_URL}/active_ping", headers=self.HEADERS, json=data)
return req.json()
@require_authentication
def audience_reply(self, channel, raise_hands=True, unraise_hands=False):
""" (Clubhouse, str, bool, bool) -> bool
Request for raise_hands.
"""
data = {
"channel": channel,
"raise_hands": raise_hands,
"unraise_hands": unraise_hands
}
req = requests.post(f"{self.API_URL}/audience_reply", headers=self.HEADERS, json=data)
return req.json()
@require_authentication
def change_handraise_settings(self, channel, is_enabled=True, handraise_permission=1):
""" (Clubhouse, bool, int) -> dict
Change handraise settings. Requires moderator privilege
handraise_permission
1: Everyone
2: Followed by the speakers
is_enabled
True: Enable handraise
False: Disable handraise
"""
handraise_permission = int(handraise_permission)
if not 1 <= handraise_permission <= 2:
return False
data = {
"channel": channel,
"is_enabled": is_enabled,
"handraise_permission": handraise_permission
}
req = requests.post(f"{self.API_URL}/change_handraise_settings", headers=self.HEADERS, json=data)
return req.json()
@require_authentication
def update_skintone(self, skintone=1):
""" (Clubhouse, int) -> dict
Updating skinetone for raising hands, etc.
"""
skintone = int(skintone)
if not 1 <= skintone <= 5:
return False
data = {
"skintone": skintone
}
req = requests.post(f"{self.API_URL}/update_skintone", headers=self.HEADERS, json=data)
return req.json()
@require_authentication
def get_notifications(self, page_size=20, page=1):
""" (Clubhouse, int, int) -> dict
Get my notifications.
"""
query = f"page_size={page_size}&page={page}"
req = requests.get(f"{self.API_URL}/get_notifications?{query}", headers=self.HEADERS)
return req.json()
@require_authentication
def get_actionable_notifications(self):
""" (Clubhouse, int, int) -> dict
Get notifications. This may return some notifications that require some actions
"""
req = requests.get(f"{self.API_URL}/get_actionable_notifications", headers=self.HEADERS)
return req.json()
@require_authentication
def get_online_friends(self):
""" (Clubhouse) -> dict
List all online friends.
"""
req = requests.post(f"{self.API_URL}/get_online_friends", headers=self.HEADERS, json={})
return req.json()
@require_authentication
def accept_speaker_invite(self, channel, user_id):
""" (Clubhouse, str, int) -> dict
Accept speaker's invitation, based on the (channel, invited_moderator)
`raise_hands` needs to be called first, prior to the invitation.
"""
data = {
"channel": channel,
"user_id": int(user_id)
}
req = requests.post(f"{self.API_URL}/accept_speaker_invite", headers=self.HEADERS, json=data)
return req.json()
@require_authentication
def reject_speaker_invite(self, channel, user_id):
""" (Clubhouse, str, int) -> dict
Reject speaker's invitation.
"""
data = {
"channel": channel,
"user_id": int(user_id)
}
req = requests.post(f"{self.API_URL}/reject_speaker_invite", headers=self.HEADERS, json=data)
return req.json()
@require_authentication
def invite_speaker(self, channel, user_id):
""" (Clubhouse, str, int) -> dict
Move audience to speaker. Requires moderator privilege.
"""
data = {
"channel": channel,
"user_id": int(user_id)
}
req = requests.post(f"{self.API_URL}/invite_speaker", headers=self.HEADERS, json=data)
return req.json()
@require_authentication
def uninvite_speaker(self, channel, user_id):
""" (Clubhouse, str, int) -> dict
Move speaker to audience. Requires moderator privilege.
"""
data = {
"channel": channel,
"user_id": int(user_id)
}
req = requests.post(f"{self.API_URL}/uninvite_speaker", headers=self.HEADERS, json=data)
return req.json()
@require_authentication
def mute_speaker(self, channel, user_id):
""" (Clubhouse, str, int) -> dict
Mute speaker. Requires moderator privilege
"""
data = {
"channel": channel,
"user_id": int(user_id)
}
req = requests.post(f"{self.API_URL}/mute_speaker", headers=self.HEADERS, json=data)
return req.json()
@require_authentication
def get_suggested_speakers(self, channel):
""" (Clubhouse, str) -> dict
Get suggested speakers from the given channel
"""
data = {
"channel": channel
}
req = requests.post(f"{self.API_URL}/get_suggested_speakers", headers=self.HEADERS, json=data)
return req.json()
@require_authentication
def create_channel(self, topic="", user_ids=(), is_private=False, is_social_mode=False):
""" (Clubhouse, str, list, bool, bool) -> dict
Create a new channel. Type of the room can be changed.
"""
data = {
"is_social_mode": is_social_mode,
"is_private": is_private,
"club_id": None,
"user_ids": user_ids,
"event_id": None,
"topic": topic
}
req = requests.post(f"{self.API_URL}/create_channel", headers=self.HEADERS, json=data)
return req.json()
@require_authentication
def get_create_channel_targets(self):
""" (Clubhouse) -> dict
Not sure what this does. Triggered during channel creation
"""
data = {}
req = requests.post(f"{self.API_URL}/get_create_channel_targets", headers=self.HEADERS, json=data)
return req.json()
@require_authentication
def get_suggested_invites(self, club_id=None, upload_contacts=True, contacts=()):
""" (Clubhouse, int, bool, list of dict) -> dict
Get invitations and user lists based on phone number.
contacts: [{"name": "Test Name", "phone_number": "+821043219876"}, ...]
"""
data = {
"club_id": club_id,
"upload_contacts": upload_contacts,
"contacts": contacts
}
req = requests.post(f"{self.API_URL}/get_suggested_invites", headers=self.HEADERS, json=data)
return req.json()
@require_authentication
def get_suggested_club_invites(self, upload_contacts=True, contacts=()):
""" (Clubhouse, int, bool, list of dict) -> dict
Get user lists based on phone number. For inviting clubs.
contacts: [{"name": "Test Name", "phone_number": "+821043219876"}, ...]
"""
data = {
"upload_contacts": upload_contacts,
"contacts": contacts
}
req = requests.post(f"{self.API_URL}/get_suggested_club_invites", headers=self.HEADERS, json=data)
return req.json()
@require_authentication
def invite_to_app(self, name, phone_number, message=None):
""" (Clubhouse, str, str, str) -> dict
Invite users to app. but this only works when you have a leftover invitation.
"""
data = {
"name": name,
"phone_number": phone_number,
"message": message
}
req = requests.post(f"{self.API_URL}/invite_to_app", headers=self.HEADERS, json=data)
return req.json()
@require_authentication
def invite_from_waitlist(self, user_id):
""" (Clubhouse, str, str, str) -> dict
Invite someone from the waitlist.
This is much more reliable than inviting someone by invite_to_app
"""
data = {
"user_id": int(user_id),
}
req = requests.post(f"{self.API_URL}/invite_from_waitlist", headers=self.HEADERS, json=data)
return req.json()
@require_authentication
def search_users(self, query, followers_only=False, following_only=False, cofollows_only=False):
""" (Clubhouse, str, bool, bool, bool) -> dict
Search users based on the given query.
"""
data = {
"cofollows_only": cofollows_only,
"following_only": following_only,
"followers_only": followers_only,
"query": query
}
req = requests.post(f"{self.API_URL}/search_users", headers=self.HEADERS, json=data)
return req.json()
@require_authentication
def search_clubs(self, query, followers_only=False, following_only=False, cofollows_only=False):
""" (Clubhouse, str, bool, bool, bool) -> dict
Search clubs based on the given query.
"""
data = {
"cofollows_only": cofollows_only,
"following_only": following_only,
"followers_only": followers_only,
"query": query
}
req = requests.post(f"{self.API_URL}/search_clubs", headers=self.HEADERS, json=data)
return req.json()
@require_authentication
def get_topic(self, topic_id):
""" (Clubhouse, int) -> dict
Get topic's information based on the given topic id.
"""
data = {
"topic_id": int(topic_id)
}
req = requests.post(f"{self.API_URL}/get_topic", headers=self.HEADERS, json=data)
return req.json()
@require_authentication
def get_clubs_for_topic(self, topic_id, page_size=25, page=1):
""" (Clubhouse, int, int, int) -> dict
Get list of clubs based on the given topic id.
"""
query = "topic_id={}&page_size={}&page={}".format(
topic_id,
page_size,
page
)
req = requests.get(f"{self.API_URL}/get_clubs_for_topic?{query}", headers=self.HEADERS)
return req.json()
@require_authentication
def get_clubs(self, is_startable_only):
""" (Clubhouse, bool) -> dict
Get list of clubs the user's in.
"""
data = {
"is_startable_only": is_startable_only
}
req = requests.post(f"{self.API_URL}/get_clubs", headers=self.HEADERS, json=data)
return req.json()
@require_authentication
def get_users_for_topic(self, topic_id, page_size=25, page=1):
""" (Clubhouse, int, int, int) -> dict
Get list of users based on the given topic id.
"""
query = "topic_id={}&page_size={}&page={}".format(
topic_id,
page_size,
page
)
req = requests.get(f"{self.API_URL}/get_users_for_topic?{query}", headers=self.HEADERS)
return req.json()