subscription.py 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  1. # mautrix-instagram - A Matrix-Instagram puppeting bridge.
  2. # Copyright (C) 2020 Tulir Asokan
  3. #
  4. # This program is free software: you can redistribute it and/or modify
  5. # it under the terms of the GNU Affero General Public License as published by
  6. # the Free Software Foundation, either version 3 of the License, or
  7. # (at your option) any later version.
  8. #
  9. # This program is distributed in the hope that it will be useful,
  10. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. # GNU Affero General Public License for more details.
  13. #
  14. # You should have received a copy of the GNU Affero General Public License
  15. # along with this program. If not, see <https://www.gnu.org/licenses/>.
  16. from typing import Any, Optional, Union
  17. from enum import Enum
  18. from uuid import uuid4
  19. import json
  20. class SkywalkerSubscription:
  21. @staticmethod
  22. def direct_sub(user_id: Union[str, int]) -> str:
  23. return f"ig/u/v1/{user_id}"
  24. @staticmethod
  25. def live_sub(user_id: Union[str, int]) -> str:
  26. return f"ig/live_notification_subscribe/{user_id}"
  27. class GraphQLQueryID(Enum):
  28. appPresence = '17846944882223835'
  29. asyncAdSub = '17911191835112000'
  30. clientConfigUpdate = '17849856529644700'
  31. directStatus = '17854499065530643'
  32. directTyping = '17867973967082385'
  33. liveWave = '17882305414154951'
  34. interactivityActivateQuestion = '18005526940184517'
  35. interactivityRealtimeQuestionSubmissionsStatus = '18027779584026952'
  36. interactivitySub = '17907616480241689'
  37. liveRealtimeComments = '17855344750227125'
  38. liveTypingIndicator = '17926314067024917'
  39. mediaFeedback = '17877917527113814'
  40. reactNativeOTA = '17861494672288167'
  41. videoCallCoWatchControl = '17878679623388956'
  42. videoCallInAlert = '17878679623388956'
  43. videoCallPrototypePublish = '18031704190010162'
  44. videoCallParticipantDelivery = '17977239895057311'
  45. zeroProvision = '17913953740109069'
  46. inappNotification = '17899377895239777'
  47. businessDelivery = '17940467278199720'
  48. everclear_subscriptions = {
  49. "async_ads_subscribe": GraphQLQueryID.asyncAdSub.value,
  50. "inapp_notification_subscribe_default": GraphQLQueryID.inappNotification.value,
  51. "inapp_notification_subscribe_comment": GraphQLQueryID.inappNotification.value,
  52. "inapp_notification_subscribe_comment_mention_and_reply": GraphQLQueryID.inappNotification.value,
  53. "business_import_page_media_delivery_subscribe": GraphQLQueryID.businessDelivery.value,
  54. "video_call_participant_state_delivery": GraphQLQueryID.videoCallParticipantDelivery.value,
  55. }
  56. class GraphQLSubscription:
  57. @staticmethod
  58. def _fmt(query_id: GraphQLQueryID, input_params: Any,
  59. client_logged: Optional[bool] = None) -> str:
  60. params = {
  61. "input_data": input_params,
  62. **({"%options": {"client_logged": client_logged}}
  63. if client_logged is not None else {}),
  64. }
  65. return f"1/graphqlsubscriptions/{query_id.value}/{json.dumps(params)}"
  66. @classmethod
  67. def app_presence(cls, subscription_id: Optional[str] = None,
  68. client_logged: Optional[bool] = None) -> str:
  69. return cls._fmt(GraphQLQueryID.appPresence,
  70. input_params={"client_subscription_id": subscription_id or str(uuid4())},
  71. client_logged=client_logged)
  72. @classmethod
  73. def async_ad(cls, user_id: str, subscription_id: Optional[str] = None,
  74. client_logged: Optional[bool] = None) -> str:
  75. return cls._fmt(GraphQLQueryID.asyncAdSub,
  76. input_params={"client_subscription_id": subscription_id or str(uuid4()),
  77. "user_id": user_id},
  78. client_logged=client_logged)
  79. @classmethod
  80. def client_config_update(cls, subscription_id: Optional[str] = None,
  81. client_logged: Optional[bool] = None) -> str:
  82. return cls._fmt(GraphQLQueryID.clientConfigUpdate,
  83. input_params={"client_subscription_id": subscription_id or str(uuid4())},
  84. client_logged=client_logged)
  85. @classmethod
  86. def direct_status(cls, subscription_id: Optional[str] = None,
  87. client_logged: Optional[bool] = None) -> str:
  88. return cls._fmt(GraphQLQueryID.directStatus,
  89. input_params={"client_subscription_id": subscription_id or str(uuid4())},
  90. client_logged=client_logged)
  91. @classmethod
  92. def direct_typing(cls, user_id: str, client_logged: Optional[bool] = None) -> str:
  93. return cls._fmt(GraphQLQueryID.directTyping,
  94. input_params={"user_id": user_id},
  95. client_logged=client_logged)
  96. @classmethod
  97. def ig_live_wave(cls, broadcast_id: str, receiver_id: str,
  98. subscription_id: Optional[str] = None, client_logged: Optional[bool] = None
  99. ) -> str:
  100. return cls._fmt(GraphQLQueryID.liveWave,
  101. input_params={"client_subscription_id": subscription_id or str(uuid4()),
  102. "broadcast_id": broadcast_id, "receiver_id": receiver_id},
  103. client_logged=client_logged)
  104. @classmethod
  105. def interactivity_activate_question(cls, broadcast_id: str,
  106. subscription_id: Optional[str] = None,
  107. client_logged: Optional[bool] = None) -> str:
  108. return cls._fmt(GraphQLQueryID.interactivityActivateQuestion,
  109. input_params={"client_subscription_id": subscription_id or str(uuid4()),
  110. "broadcast_id": broadcast_id},
  111. client_logged=client_logged)
  112. @classmethod
  113. def interactivity_realtime_question_submissions_status(
  114. cls, broadcast_id: str, subscription_id: Optional[str] = None,
  115. client_logged: Optional[bool] = None
  116. ) -> str:
  117. return cls._fmt(GraphQLQueryID.interactivityRealtimeQuestionSubmissionsStatus,
  118. input_params={"client_subscription_id": subscription_id or str(uuid4()),
  119. "broadcast_id": broadcast_id},
  120. client_logged=client_logged)
  121. @classmethod
  122. def interactivity(cls, broadcast_id: str, subscription_id: Optional[str] = None,
  123. client_logged: Optional[bool] = None) -> str:
  124. return cls._fmt(GraphQLQueryID.interactivitySub,
  125. input_params={"client_subscription_id": subscription_id or str(uuid4()),
  126. "broadcast_id": broadcast_id},
  127. client_logged=client_logged)
  128. @classmethod
  129. def live_realtime_comments(cls, broadcast_id: str, subscription_id: Optional[str] = None,
  130. client_logged: Optional[bool] = None) -> str:
  131. return cls._fmt(GraphQLQueryID.liveRealtimeComments,
  132. input_params={"client_subscription_id": subscription_id or str(uuid4()),
  133. "broadcast_id": broadcast_id},
  134. client_logged=client_logged)
  135. @classmethod
  136. def live_realtime_typing_indicator(cls, broadcast_id: str,
  137. subscription_id: Optional[str] = None,
  138. client_logged: Optional[bool] = None) -> str:
  139. return cls._fmt(GraphQLQueryID.liveTypingIndicator,
  140. input_params={"client_subscription_id": subscription_id or str(uuid4()),
  141. "broadcast_id": broadcast_id},
  142. client_logged=client_logged)
  143. @classmethod
  144. def media_feedback(cls, feedback_id: str, subscription_id: Optional[str] = None,
  145. client_logged: Optional[bool] = None) -> str:
  146. return cls._fmt(GraphQLQueryID.mediaFeedback,
  147. input_params={"client_subscription_id": subscription_id or str(uuid4()),
  148. "feedback_id": feedback_id},
  149. client_logged=client_logged)
  150. @classmethod
  151. def react_native_ota_update(cls, build_number: str, subscription_id: Optional[str] = None,
  152. client_logged: Optional[bool] = None) -> str:
  153. return cls._fmt(GraphQLQueryID.reactNativeOTA,
  154. input_params={"client_subscription_id": subscription_id or str(uuid4()),
  155. "build_number": build_number},
  156. client_logged=client_logged)
  157. @classmethod
  158. def video_call_co_watch_control(cls, video_call_id: str, subscription_id: Optional[str] = None,
  159. client_logged: Optional[bool] = None) -> str:
  160. return cls._fmt(GraphQLQueryID.videoCallCoWatchControl,
  161. input_params={"client_subscription_id": subscription_id or str(uuid4()),
  162. "video_call_id": video_call_id},
  163. client_logged=client_logged)
  164. @classmethod
  165. def video_call_in_call_alert(cls, video_call_id: str, subscription_id: Optional[str] = None,
  166. client_logged: Optional[bool] = None) -> str:
  167. return cls._fmt(GraphQLQueryID.videoCallInAlert,
  168. input_params={"client_subscription_id": subscription_id or str(uuid4()),
  169. "video_call_id": video_call_id},
  170. client_logged=client_logged)
  171. @classmethod
  172. def video_call_prototype_publish(cls, video_call_id: str,
  173. subscription_id: Optional[str] = None,
  174. client_logged: Optional[bool] = None) -> str:
  175. return cls._fmt(GraphQLQueryID.videoCallPrototypePublish,
  176. input_params={"client_subscription_id": subscription_id or str(uuid4()),
  177. "video_call_id": video_call_id},
  178. client_logged=client_logged)
  179. @classmethod
  180. def zero_provision(cls, device_id: str, subscription_id: Optional[str] = None,
  181. client_logged: Optional[bool] = None) -> str:
  182. return cls._fmt(GraphQLQueryID.zeroProvision,
  183. input_params={"client_subscription_id": subscription_id or str(uuid4()),
  184. "device_id": device_id},
  185. client_logged=client_logged)