mirror of
https://github.com/aiogram/aiogram.git
synced 2025-12-11 18:01:04 +00:00
Provide sendMessage and deleteMessage methods.
This commit is contained in:
parent
79edeaf960
commit
e87180b6f4
3 changed files with 43 additions and 2 deletions
|
|
@ -56,7 +56,7 @@ class ApiMethods:
|
||||||
SET_WEBHOOK = 'setWebhook' # TODO
|
SET_WEBHOOK = 'setWebhook' # TODO
|
||||||
DELETE_WEBHOOK = 'deleteWebhook' # TODO
|
DELETE_WEBHOOK = 'deleteWebhook' # TODO
|
||||||
GET_WEBHOOK_INFO = 'getWebhookInfo' # TODO
|
GET_WEBHOOK_INFO = 'getWebhookInfo' # TODO
|
||||||
SEND_MESSAGE = 'sendMessage' # TODO
|
SEND_MESSAGE = 'sendMessage'
|
||||||
FORWARD_MESSAGE = 'forwardMessage' # TODO
|
FORWARD_MESSAGE = 'forwardMessage' # TODO
|
||||||
SEND_PHOTO = 'sendPhoto' # TODO
|
SEND_PHOTO = 'sendPhoto' # TODO
|
||||||
SEND_AUDIO = 'sendAudio' # TODO
|
SEND_AUDIO = 'sendAudio' # TODO
|
||||||
|
|
@ -82,4 +82,4 @@ class ApiMethods:
|
||||||
EDIT_MESSAGE_TEXT = 'editMessageText' # TODO
|
EDIT_MESSAGE_TEXT = 'editMessageText' # TODO
|
||||||
EDIT_MESSAGE_CAPTION = 'editMessageCaption' # TODO
|
EDIT_MESSAGE_CAPTION = 'editMessageCaption' # TODO
|
||||||
EDIT_MESSAGE_REPLY_MARKUP = 'editMessageReplyMarkup' # TODO
|
EDIT_MESSAGE_REPLY_MARKUP = 'editMessageReplyMarkup' # TODO
|
||||||
DELETE_MESSAGE = 'deleteMessage' # TODO
|
DELETE_MESSAGE = 'deleteMessage'
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@ import signal
|
||||||
|
|
||||||
import aiohttp
|
import aiohttp
|
||||||
|
|
||||||
|
from aiogram.types.message import Message
|
||||||
from aiogram.utils.payload import generate_payload
|
from aiogram.utils.payload import generate_payload
|
||||||
from . import api
|
from . import api
|
||||||
from .api import ApiMethods
|
from .api import ApiMethods
|
||||||
|
|
@ -69,3 +70,30 @@ class AIOGramBot:
|
||||||
payload = generate_payload(**locals())
|
payload = generate_payload(**locals())
|
||||||
raw = await self.request(ApiMethods.GET_UPDATES, payload)
|
raw = await self.request(ApiMethods.GET_UPDATES, payload)
|
||||||
return [self.prepare_object(Update.de_json(raw_update)) for raw_update in raw]
|
return [self.prepare_object(Update.de_json(raw_update)) for raw_update in raw]
|
||||||
|
|
||||||
|
async def send_message(self, chat_id, text, parse_mode=None, disable_web_page_preview=None,
|
||||||
|
disable_notification=None, reply_to_message_id=None, reply_markup=None):
|
||||||
|
"""
|
||||||
|
chat_id Integer or String Yes Unique identifier for the target chat or username of the target channel (in the format @channelusername)
|
||||||
|
text String Yes Text of the message to be sent
|
||||||
|
parse_mode String Optional Send Markdown or HTML, if you want Telegram apps to show bold, italic, fixed-width text or inline URLs in your bot's message.
|
||||||
|
disable_web_page_preview Boolean Optional Disables link previews for links in this message
|
||||||
|
disable_notification Boolean Optional Sends the message silently. iOS users will not receive a notification, Android users will receive a notification with no sound.
|
||||||
|
reply_to_message_id Integer Optional If the message is a reply, ID of the original message
|
||||||
|
reply_markup InlineKeyboardMarkup or ReplyKeyboardMarkup or ReplyKeyboardRemove or ForceReply Optional Additional interface options. A JSON-serialized object for an inline keyboard, custom reply keyboard, instructions to remove reply keyboard or to force a reply from the user.
|
||||||
|
:return:
|
||||||
|
"""
|
||||||
|
|
||||||
|
payload = generate_payload(**locals())
|
||||||
|
|
||||||
|
if reply_markup:
|
||||||
|
# TODO: convert markup
|
||||||
|
pass
|
||||||
|
|
||||||
|
message = await self.request(ApiMethods.SEND_MESSAGE, payload)
|
||||||
|
return self.prepare_object(Message.de_json(message))
|
||||||
|
|
||||||
|
async def delete_message(self, chat_id, message_id):
|
||||||
|
payload = generate_payload(**locals())
|
||||||
|
|
||||||
|
return await self.request(ApiMethods.DELETE_MESSAGE, payload)
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
import datetime
|
import datetime
|
||||||
|
|
||||||
|
from aiogram.exceptions import TelegramAPIError
|
||||||
from . import Deserializable
|
from . import Deserializable
|
||||||
from .chat import Chat
|
from .chat import Chat
|
||||||
from .message_entity import MessageEntity
|
from .message_entity import MessageEntity
|
||||||
|
|
@ -157,6 +158,18 @@ class Message(Deserializable):
|
||||||
def is_command(self):
|
def is_command(self):
|
||||||
return self.text and self.text.startswith('/')
|
return self.text and self.text.startswith('/')
|
||||||
|
|
||||||
|
async def reply(self, text, parse_mode=None, disable_web_page_preview=None,
|
||||||
|
disable_notification=None, reply_markup=None) -> 'Message':
|
||||||
|
return await self.bot.send_message(self.chat.id, text, parse_mode, disable_web_page_preview,
|
||||||
|
disable_notification, self.message_id, reply_markup)
|
||||||
|
|
||||||
|
async def delete(self):
|
||||||
|
try:
|
||||||
|
await self.bot.delete_message(self.chat.id, self.message_id)
|
||||||
|
except TelegramAPIError:
|
||||||
|
return False
|
||||||
|
return True
|
||||||
|
|
||||||
|
|
||||||
class ContentType:
|
class ContentType:
|
||||||
TEXT = 'text'
|
TEXT = 'text'
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue