本文整理汇总了Python中bot.Bot.sendMessage方法的典型用法代码示例。如果您正苦于以下问题:Python Bot.sendMessage方法的具体用法?Python Bot.sendMessage怎么用?Python Bot.sendMessage使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类bot.Bot
的用法示例。
在下文中一共展示了Bot.sendMessage方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from bot import Bot [as 别名]
# 或者: from bot.Bot import sendMessage [as 别名]
class Control:
def __init__(self, name):
self.bot = Bot(None)
self.name = name
def process(self, query):
assert query.data.startswith(self.name)
user = query.from_
if query.message:
msg_identifier = (str(user.id), str(query.message.message_id))
else:
msg_identifier = str(query.inline_message_id)
data = query.data.split('#')[1]
if not data:
self.bot.answerCallbackQuery(query.id, '', '')
return
answer_text, show_alert = None, None
try:
result = self._process(data)
assert isinstance(result, ProcessResult)
answer_text, show_alert, to_update = result
if to_update == UPDATE_TEXT:
self.bot.editMessageText(
msg_identifier,
self._get_text(data),
reply_markup=self.get_inline_kb(data)
)
elif to_update == UPDATE_CAPTION:
self.bot.editMessageCaption(
msg_identifier,
self._get_caption(data),
reply_markup=self.get_inline_kb(data)
)
elif to_update == UPDATE_REPLY_MARKUP:
self.bot.editMessageReplyMarkup(
msg_identifier,
reply_markup=self.get_inline_kb(data)
)
except TelegramError as e:
if e.args[0] != 'Bad Request: message is not modified':
traceback.print_exc()
raise e
if answer_text:
self.bot.answerCallbackQuery(query.id, answer_text, show_alert)
def send(self, user_id):
self.bot.sendMessage(
user_id,
self._get_text(),
reply_markup=self.get_inline_kb()
)
def get_inline_kb(self, *args):
kb = self._get_inline_kb(*args)
if kb:
new_kb = []
for row in kb:
new_row = []
for b in row:
assert isinstance(b, InlineKeyboardButton)
new_b = InlineKeyboardButton(
text=b.text,
url=b.url,
callback_data=self.name + '#' + b.callback_data,
switch_inline_query=b.switch_inline_query
)
new_row.append(new_b)
new_kb.append(new_row)
return InlineKeyboardMarkup(inline_keyboard=new_kb)
return None
def _get_inline_kb(self, *args):
raise NotImplementedError
def _process(self, data):
raise NotImplementedError
def _get_text(self, *args):
raise NotImplementedError
def _get_caption(self, *args):
raise NotImplementedError