python-telegram-bot/telegram/choseninlineresult.py

82 lines
3.1 KiB
Python
Raw Normal View History

2016-01-04 17:31:06 +01:00
#!/usr/bin/env python
# pylint: disable=R0902,R0912,R0913
#
# A library that provides a Python interface to the Telegram Bot API
# Copyright (C) 2015-2018
# Leandro Toledo de Souza <devs@python-telegram-bot.org>
2016-01-04 17:31:06 +01:00
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Lesser Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Lesser Public License for more details.
#
# You should have received a copy of the GNU Lesser Public License
# along with this program. If not, see [http://www.gnu.org/licenses/].
"""This module contains an object that represents a Telegram ChosenInlineResult."""
2016-01-04 17:31:06 +01:00
2016-04-14 07:21:00 +02:00
from telegram import TelegramObject, User, Location
2016-01-04 17:31:06 +01:00
class ChosenInlineResult(TelegramObject):
"""
Represents a result of an inline query that was chosen by the user and sent to their chat
partner.
2016-01-04 17:31:06 +01:00
Note:
In Python `from` is a reserved word, use `from_user` instead.
2016-01-04 17:31:06 +01:00
Attributes:
result_id (:obj:`str`): The unique identifier for the result that was chosen.
from_user (:class:`telegram.User`): The user that chose the result.
location (:class:`telegram.Location`): Optional. Sender location.
inline_message_id (:obj:`str`): Optional. Identifier of the sent inline message.
query (:obj:`str`): The query that was used to obtain the result.
2016-01-04 17:31:06 +01:00
Args:
result_id (:obj:`str`): The unique identifier for the result that was chosen.
from_user (:class:`telegram.User`): The user that chose the result.
location (:class:`telegram.Location`, optional): Sender location, only for bots that
require user location.
inline_message_id (:obj:`str`, optional): Identifier of the sent inline message. Available
only if there is an inline keyboard attached to the message. Will be also received in
callback queries and can be used to edit the message.
query (:obj:`str`): The query that was used to obtain the result.
**kwargs (:obj:`dict`): Arbitrary keyword arguments.
2017-09-01 08:43:08 +02:00
2016-01-04 17:31:06 +01:00
"""
2016-05-24 01:43:17 +02:00
def __init__(self,
result_id,
from_user,
query,
location=None,
inline_message_id=None,
**kwargs):
2016-01-04 17:31:06 +01:00
# Required
self.result_id = result_id
2016-01-04 17:31:06 +01:00
self.from_user = from_user
self.query = query
2016-04-14 07:21:00 +02:00
# Optionals
self.location = location
self.inline_message_id = inline_message_id
2016-01-04 17:31:06 +01:00
self._id_attrs = (self.result_id,)
@classmethod
def de_json(cls, data, bot):
2016-01-04 17:31:06 +01:00
if not data:
return None
2016-04-14 08:40:26 +02:00
data = super(ChosenInlineResult, cls).de_json(data, bot)
# Required
data['from_user'] = User.de_json(data.pop('from'), bot)
2016-04-14 08:40:26 +02:00
# Optionals
data['location'] = Location.de_json(data.get('location'), bot)
return cls(**data)