本文整理汇总了Python中telegram.error.TelegramError方法的典型用法代码示例。如果您正苦于以下问题:Python error.TelegramError方法的具体用法?Python error.TelegramError怎么用?Python error.TelegramError使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类telegram.error
的用法示例。
在下文中一共展示了error.TelegramError方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_me
# 需要导入模块: from telegram import error [as 别名]
# 或者: from telegram.error import TelegramError [as 别名]
def get_me(self, timeout=None, **kwargs):
"""A simple method for testing your bot's auth token. Requires no parameters.
Args:
timeout (:obj:`int` | :obj:`float`, optional): If this value is specified, use it as
the read timeout from the server (instead of the one specified during creation of
the connection pool).
Returns:
:class:`telegram.User`: A :class:`telegram.User` instance representing that bot if the
credentials are valid, :obj:`None` otherwise.
Raises:
:class:`telegram.TelegramError`
"""
url = '{0}/getMe'.format(self.base_url)
result = self._request.get(url, timeout=timeout)
self.bot = User.de_json(result, self)
return self.bot
示例2: delete_webhook
# 需要导入模块: from telegram import error [as 别名]
# 或者: from telegram.error import TelegramError [as 别名]
def delete_webhook(self, timeout=None, **kwargs):
"""
Use this method to remove webhook integration if you decide to switch back to
getUpdates. Requires no parameters.
Args:
timeout (:obj:`int` | :obj:`float`, optional): If this value is specified, use it as
the read timeout from the server (instead of the one specified during creation of
the connection pool).
**kwargs (:obj:`dict`): Arbitrary keyword arguments.
Returns:
:obj:`bool` On success, ``True`` is returned.
Raises:
:class:`telegram.TelegramError`
"""
url = '{0}/deleteWebhook'.format(self.base_url)
data = kwargs
result = self._request.post(url, data, timeout=timeout)
return result
示例3: delete_sticker_from_set
# 需要导入模块: from telegram import error [as 别名]
# 或者: from telegram.error import TelegramError [as 别名]
def delete_sticker_from_set(self, sticker, timeout=None, **kwargs):
"""Use this method to delete a sticker from a set created by the bot.
Args:
sticker (:obj:`str`): File identifier of the sticker.
timeout (:obj:`int` | :obj:`float`, optional): If this value is specified, use it as
the read timeout from the server (instead of the one specified during
creation of the connection pool).
**kwargs (:obj:`dict`): Arbitrary keyword arguments.
Returns:
:obj:`bool`: On success, ``True`` is returned.
Raises:
:class:`telegram.TelegramError`
"""
url = '{0}/deleteStickerFromSet'.format(self.base_url)
data = {'sticker': sticker}
data.update(kwargs)
result = self._request.post(url, data, timeout=timeout)
return result
示例4: file_id_query_received
# 需要导入模块: from telegram import error [as 别名]
# 或者: from telegram.error import TelegramError [as 别名]
def file_id_query_received(update: Update, context: CallbackContext):
# get query
query = update.inline_query
user_id = query.from_user.id
results = None
try:
file = bot.get_file(query.query)
_id = uuid.uuid4()
title = get_message(user_id, "your_sticker")
desc = get_message(user_id, "forward_desc")
caption = "@EzStickerBot"
results = [InlineQueryResultCachedDocument(_id, title, file.file_id, description=desc, caption=caption)]
query.answer(results=results, cache_time=5, is_personal=True)
# if file_id wasn't found show share option
except TelegramError:
share_query_received(update, context)
示例5: error_callback
# 需要导入模块: from telegram import error [as 别名]
# 或者: from telegram.error import TelegramError [as 别名]
def error_callback(bot, update, error):
try:
raise error
except Unauthorized:
print("no nono1")
print(error)
# remove update.message.chat_id from conversation list
except BadRequest:
print("no nono2")
print("BadRequest caught")
print(error)
# handle malformed requests - read more below!
except TimedOut:
print("no nono3")
# handle slow connection problems
except NetworkError:
print("no nono4")
# handle other connection problems
except ChatMigrated as err:
print("no nono5")
print(err)
# the chat_id of a group has changed, use e.new_chat_id instead
except TelegramError:
print(error)
# handle all other telegram related errors
示例6: send_to_list
# 需要导入模块: from telegram import error [as 别名]
# 或者: from telegram.error import TelegramError [as 别名]
def send_to_list(bot: Bot, send_to: list, message: str, markdown=False, html=False) -> None:
if html and markdown:
raise Exception("Can only send with either markdown or HTML!")
for user_id in set(send_to):
try:
if markdown:
bot.send_message(user_id, message, parse_mode=ParseMode.MARKDOWN)
elif html:
bot.send_message(user_id, message, parse_mode=ParseMode.HTML)
else:
bot.send_message(user_id, message)
except TelegramError:
pass # ignore users who fail
示例7: finish
# 需要导入模块: from telegram import error [as 别名]
# 或者: from telegram.error import TelegramError [as 别名]
def finish(self):
# set last update
self.channel.last_update = datetime.date.today()
self._save_channel()
new_bots = Bot.select_new_bots()
if not self.silent and len(new_bots) > 0:
self.notify_admin("Sending notifications to subscribers...")
subscribers = Notifications.select().where(Notifications.enabled == True)
notification_count = 0
for sub in subscribers:
try:
util.send_md_message(self.bot, sub.chat_id,
messages.BOTLIST_UPDATE_NOTIFICATION.format(
n_bots=len(new_bots),
new_bots=Bot.get_new_bots_markdown()))
notification_count += 1
sub.last_notification = datetime.date.today()
sub.save()
except TelegramError:
pass
self.sent['notifications'] = "Notifications sent to {} users.".format(
notification_count)
changes_made = len(self.sent) > 1 or len(self.sent['category']) > 0
if changes_made:
text = util.success('{}{}'.format('BotList updated successfully:\n\n',
mdformat.results_list(self.sent)))
else:
text = mdformat.none_action("No changes were necessary.")
log.info(self.sent)
self.bot.formatter.send_or_edit(self.chat_id, text, to_edit=self.message_id)
示例8: check_requirements
# 需要导入模块: from telegram import error [as 别名]
# 或者: from telegram.error import TelegramError [as 别名]
def check_requirements(self):
try:
self.bot.get_me()
self.bot.send_message(chat_id=self.chat_id, text="Kimsufi Crawler started")
except TelegramError as te:
_logger.error("Telegram validation failed: {error}".format(error=te.message))
raise
示例9: notify
# 需要导入模块: from telegram import error [as 别名]
# 或者: from telegram.error import TelegramError [as 别名]
def notify(self, title, text, url=None):
try:
self.bot.send_message(chat_id=self.chat_id, text=text)
except TelegramError as te:
_logger.error("Something went wrong sending the message to Telegram:")
_logger.error(te)
示例10: delete_message
# 需要导入模块: from telegram import error [as 别名]
# 或者: from telegram.error import TelegramError [as 别名]
def delete_message(self, chat_id, message_id, timeout=None, **kwargs):
"""
Use this method to delete a message. A message can only be deleted if it was sent less
than 48 hours ago. Any such recently sent outgoing message may be deleted. Additionally,
if the bot is an administrator in a group chat, it can delete any message. If the bot is
an administrator in a supergroup, it can delete messages from any other user and service
messages about people joining or leaving the group (other types of service messages may
only be removed by the group creator). In channels, bots can only remove their own
messages.
Args:
chat_id (:obj:`int` | :obj:`str`): Unique identifier for the target chat or username
of the target channel (in the format @channelusername).
message_id (:obj:`int`): Identifier of the message to delete.
timeout (:obj:`int` | :obj:`float`, optional): If this value is specified, use it as
the read timeout
from the server (instead of the one specified during creation of the connection
pool).
**kwargs (:obj:`dict`): Arbitrary keyword arguments.
Returns:
:obj:`bool`: On success, ``True`` is returned.
Raises:
:class:`telegram.TelegramError`
"""
url = '{0}/deleteMessage'.format(self.base_url)
data = {'chat_id': chat_id, 'message_id': message_id}
result = self._request.post(url, data, timeout=timeout)
return result
示例11: send_game
# 需要导入模块: from telegram import error [as 别名]
# 或者: from telegram.error import TelegramError [as 别名]
def send_game(self,
chat_id,
game_short_name,
disable_notification=False,
reply_to_message_id=None,
reply_markup=None,
timeout=None,
**kwargs):
"""Use this method to send a game.
Args:
chat_id (:obj:`int` | :obj:`str`): Unique identifier for the target chat or username
of the target channel (in the format @channelusername).
game_short_name (:obj:`str`): Short name of the game, serves as the unique identifier
for the game. Set up your games via Botfather.
disable_notification (:obj:`bool`, optional): Sends the message silently. Users will
receive a notification with no sound.
reply_to_message_id (:obj:`int`, optional): If the message is a reply, ID of the
original message.
reply_markup (:class:`telegram.ReplyMarkup`, 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.
timeout (:obj:`int` | :obj:`float`, optional): If this value is specified, use it as
the read timeout from the server (instead of the one specified during creation of
the connection pool).
**kwargs (:obj:`dict`): Arbitrary keyword arguments.
Returns:
:class:`telegram.Message`: On success, the sent Message is returned.
Raises:
:class:`telegram.TelegramError`
"""
url = '{0}/sendGame'.format(self.base_url)
data = {'chat_id': chat_id, 'game_short_name': game_short_name}
return url, data
示例12: get_user_profile_photos
# 需要导入模块: from telegram import error [as 别名]
# 或者: from telegram.error import TelegramError [as 别名]
def get_user_profile_photos(self, user_id, offset=None, limit=100, timeout=None, **kwargs):
"""Use this method to get a list of profile pictures for a user.
Args:
user_id (:obj:`int`): Unique identifier of the target user.
offset (:obj:`int`, optional): Sequential number of the first photo to be returned.
By default, all photos are returned.
limit (:obj:`int`, optional): Limits the number of photos to be retrieved. Values
between 1-100 are accepted. Defaults to 100.
timeout (:obj:`int` | :obj:`float`, optional): If this value is specified, use it as
the read timeout from the server (instead of the one specified during creation of
the connection pool).
**kwargs (:obj:`dict`): Arbitrary keyword arguments.
Returns:
:class:`telegram.UserProfilePhotos`
Raises:
:class:`telegram.TelegramError`
"""
url = '{0}/getUserProfilePhotos'.format(self.base_url)
data = {'user_id': user_id}
if offset is not None:
data['offset'] = offset
if limit:
data['limit'] = limit
data.update(kwargs)
result = self._request.post(url, data, timeout=timeout)
return UserProfilePhotos.de_json(result, self)
示例13: get_file
# 需要导入模块: from telegram import error [as 别名]
# 或者: from telegram.error import TelegramError [as 别名]
def get_file(self, file_id, timeout=None, **kwargs):
"""
Use this method to get basic info about a file and prepare it for downloading. For the
moment, bots can download files of up to 20MB in size. The file can then be downloaded
with :attr:`telegram.File.download`. It is guaranteed that the link will be
valid for at least 1 hour. When the link expires, a new one can be requested by
calling getFile again.
Args:
file_id (:obj:`str`): File identifier to get info about.
timeout (:obj:`int` | :obj:`float`, optional): If this value is specified, use it as
the read timeout from the server (instead of the one specified during creation of
the connection pool).
**kwargs (:obj:`dict`): Arbitrary keyword arguments.
Returns:
:class:`telegram.File`
Raises:
:class:`telegram.TelegramError`
"""
url = '{0}/getFile'.format(self.base_url)
data = {'file_id': file_id}
data.update(kwargs)
result = self._request.post(url, data, timeout=timeout)
if result.get('file_path'):
result['file_path'] = '%s/%s' % (self.base_file_url, result['file_path'])
return File.de_json(result, self)
示例14: unban_chat_member
# 需要导入模块: from telegram import error [as 别名]
# 或者: from telegram.error import TelegramError [as 别名]
def unban_chat_member(self, chat_id, user_id, timeout=None, **kwargs):
"""Use this method to unban a previously kicked user in a supergroup.
The user will not return to the group automatically, but will be able to join via link,
etc. The bot must be an administrator in the group for this to work.
Args:
chat_id (:obj:`int` | :obj:`str`): Unique identifier for the target chat or username
of the target channel (in the format @channelusername).
user_id (:obj:`int`): Unique identifier of the target user.
timeout (:obj:`int` | :obj:`float`, optional): If this value is specified, use it as
the read timeout from the server (instead of the one specified during creation of
the connection pool).
**kwargs (:obj:`dict`): Arbitrary keyword arguments.
Returns:
:obj:`bool` On success, ``True`` is returned.
Raises:
:class:`telegram.TelegramError`
"""
url = '{0}/unbanChatMember'.format(self.base_url)
data = {'chat_id': chat_id, 'user_id': user_id}
data.update(kwargs)
result = self._request.post(url, data, timeout=timeout)
return result
示例15: leave_chat
# 需要导入模块: from telegram import error [as 别名]
# 或者: from telegram.error import TelegramError [as 别名]
def leave_chat(self, chat_id, timeout=None, **kwargs):
"""Use this method for your bot to leave a group, supergroup or channel.
Args:
chat_id (:obj:`int` | :obj:`str`): Unique identifier for the target chat or username
of the target`channel (in the format @channelusername).
timeout (:obj:`int` | :obj:`float`, optional): If this value is specified, use it as
the read timeout from the server (instead of the one specified during creation of
the connection pool).
**kwargs (:obj:`dict`): Arbitrary keyword arguments.
Returns:
:obj:`bool` On success, ``True`` is returned.
Raises:
:class:`telegram.TelegramError`
"""
url = '{0}/leaveChat'.format(self.base_url)
data = {'chat_id': chat_id}
data.update(kwargs)
result = self._request.post(url, data, timeout=timeout)
return result