Add send_audio method

This commit is contained in:
Dan 2017-12-14 10:57:30 +01:00
parent a5d1b7f480
commit 60dc1e577c

View File

@ -20,6 +20,7 @@ import base64
import json
import logging
import math
import mimetypes
import os
import time
from collections import namedtuple
@ -256,6 +257,8 @@ class Client:
self.rnd_id = self.session.msg_id
self.get_dialogs()
mimetypes.init()
def stop(self):
self.session.stop()
@ -563,3 +566,35 @@ class Client:
random_id=self.rnd_id()
)
)
def send_audio(self,
chat_id: int or str,
audio: str,
caption: str = "",
duration: int = 0,
performer: str = None,
title: str = None,
disable_notification: bool = None,
reply_to_message_id: int = None):
return self.send(
functions.messages.SendMedia(
peer=self.resolve_peer(chat_id),
media=types.InputMediaUploadedDocument(
mime_type=mimetypes.types_map["." + audio.split(".")[-1]],
file=self.save_file(audio),
caption=caption,
attributes=[
types.DocumentAttributeAudio(
duration=duration,
performer=performer,
title=title
),
types.DocumentAttributeFilename(os.path.basename(audio))
]
),
silent=disable_notification or None,
reply_to_msg_id=reply_to_message_id,
random_id=self.rnd_id()
)
)