Untitled
unknown
python
2 years ago
3.9 kB
1
Indexable
Never
def send_message(self, chatId: str, message: str = None, messageType: int = 0, file: BinaryIO = None, fileType: str = None, replyTo: str = None, mentionUserIds: list = None, stickerId: str = None, embedId: str = None, embedType: int = None, embedLink: str = None, embedTitle: str = None, embedContent: str = None, embedImage: BinaryIO = None,snippetLink: str = None, ytVideo: str = None, snippetImage: BinaryIO = None): """ Send a Message to a Chat. **Parameters** - **message** : Message to be sent - **chatId** : ID of the Chat. - **file** : File to be sent. - **fileType** : Type of the file. - ``audio``, ``image``, ``gif`` - **messageType** : Type of the Message. - **mentionUserIds** : List of User IDS to mention. '@' needed in the Message. - **replyTo** : Message ID to reply to. - **stickerId** : Sticker ID to be sent. - **embedTitle** : Title of the Embed. - **embedContent** : Content of the Embed. - **embedLink** : Link of the Embed. - **embedImage** : Image of the Embed. - **embedId** : ID of the Embed. **Returns** - **Success** : 200 (int) - **Fail** : :meth:`Exceptions <amino.lib.util.exceptions>` """ if message is not None and file is None: message = message.replace("<$", "").replace("$>", "") mentions = [] if mentionUserIds: for mention_uid in mentionUserIds: mentions.append({"uid": mention_uid}) if embedImage: embedImage = [[100, self.upload_media(embedImage, "image"), None]] data = { "type": messageType, "content": message, "clientRefId": int(timestamp() / 10 % 1000000000), "attachedObject": { "objectId": embedId, "objectType": embedType, "link": embedLink, "title": embedTitle, "content": embedContent, "mediaList": embedImage }, "extensions": {"mentionedArray": mentions}, "timestamp": int(timestamp() * 1000) } if replyTo: data["replyMessageId"] = replyTo if snippetLink and snippetImage: data["attachedObject"] = None data["extensions"]["linkSnippetList"] = [{ "link": snippetLink, "mediaType": 100, "mediaUploadValue": base64.b64encode(snippetImage.read()).decode(), "mediaUploadValueContentType": "image/png" }] if stickerId: data["content"] = None data["stickerId"] = stickerId data["type"] = 3 if file: data["content"] = None if fileType == "audio": data["type"] = 2 data["mediaType"] = 110 elif fileType == "image": data["mediaType"] = 100 data["mediaUploadValueContentType"] = "image/jpg" data["mediaUhqEnabled"] = True elif fileType == "gif": data["mediaType"] = 100 data["mediaUploadValueContentType"] = "image/gif" data["mediaUhqEnabled"] = True else: raise exceptions.SpecifyType(fileType) data["mediaUploadValue"] = base64.b64encode(file.read()).decode() data = json.dumps(data) response = requests.post(f"{self.api}/x{self.comId}/s/chat/thread/{chatId}/message", headers=self.parse_headers(data=data,deviceId=self.dev()), data=data, proxies=self.proxies, verify=self.certificatePath) if response.status_code != 200: return exceptions.Check