def get_inline_bot_results(self, bot: Union[int, str], query: str = "", offset: str = "", latitude: float = None, longitude: float = None): """Get bot results via inline queries. You can then send a result using :obj:`send_inline_bot_result <pyrogram.Client.send_inline_bot_result>` Parameters: bot (``int`` | ``str``): Unique identifier of the inline bot you want to get results from. You can specify a @username (str) or a bot ID (int). query (``str``, *optional*): Text of the query (up to 512 characters). Defaults to "" (empty string). offset (``str``, *optional*): Offset of the results to be returned. latitude (``float``, *optional*): Latitude of the location. Useful for location-based results only. longitude (``float``, *optional*): Longitude of the location. Useful for location-based results only. Returns: :obj:`BotResults <pyrogram.api.types.messages.BotResults>`: On Success. Raises: TimeoutError: In case the bot fails to answer within 10 seconds. Example: .. code-block:: python results = app.get_inline_bot_results("pyrogrambot") print(results) """ # TODO: Don't return the raw type try: return self.send( functions.messages.GetInlineBotResults( bot=self.resolve_peer(bot), peer=types.InputPeerSelf(), query=query, offset=offset, geo_point=types.InputGeoPoint(lat=latitude, long=longitude) if (latitude is not None and longitude is not None) else None)) except UnknownError as e: # TODO: Add this -503 Timeout error into the Error DB if e.x.error_code == -503 and e.x.error_message == "Timeout": raise TimeoutError( "The inline bot didn't answer in time") from None else: raise e
def send_location(self, chat_id: int or str, latitude: float, longitude: float, disable_notification: bool = None, reply_to_message_id: int = None, reply_markup=None): """Use this method to send points on the map. Args: chat_id (``int`` | ``str``): Unique identifier (int) or username (str) of the target chat. For your personal cloud (Saved Messages) you can simply use "me" or "self". For a contact that exists in your Telegram address book you can use his phone number (str). latitude (``float``): Latitude of the location. longitude (``float``): Longitude of the location. disable_notification (``bool``, *optional*): Sends the message silently. Users will receive a notification with no sound. reply_to_message_id (``int``, *optional*): If the message is a reply, ID of the original message reply_markup (:obj:`InlineKeyboardMarkup` | :obj:`ReplyKeyboardMarkup` | :obj:`ReplyKeyboardRemove` | :obj:`ForceReply`, *optional*): Additional interface options. An object for an inline keyboard, custom reply keyboard, instructions to remove reply keyboard or to force a reply from the user. Returns: On success, the sent :obj:`Message <pyrogram.Message>` is returned. Raises: :class:`Error <pyrogram.Error>` """ r = self.send( functions.messages.SendMedia( peer=self.resolve_peer(chat_id), media=types.InputMediaGeoPoint( types.InputGeoPoint(latitude, longitude)), message="", silent=disable_notification or None, reply_to_msg_id=reply_to_message_id, random_id=self.rnd_id(), reply_markup=reply_markup.write() if reply_markup else None)) for i in r.updates: if isinstance( i, (types.UpdateNewMessage, types.UpdateNewChannelMessage)): return utils.parse_messages(self, i.message, {i.id: i for i in r.users}, {i.id: i for i in r.chats})
async def get_nearby_chats( self, latitude: float, longitude: float ) -> List["pyrogram.Chat"]: """Get nearby chats. Parameters: latitude (``float``): Latitude of the location. longitude (``float``): Longitude of the location. Returns: List of :obj:`Chat`: On success, a list of nearby chats is returned. Example: .. code-block:: python chats = app.get_nearby_chats(51.500729, -0.124583) print(chats) """ r = await self.send( functions.contacts.GetLocated( geo_point=types.InputGeoPoint( lat=latitude, long=longitude ) ) ) if not r.updates: return [] chats = pyrogram.List([pyrogram.Chat._parse_chat(self, chat) for chat in r.chats]) peers = r.updates[0].peers for peer in peers: chat_id = utils.get_channel_id(peer.peer.channel_id) for chat in chats: if chat.id == chat_id: chat.distance = peer.distance break return chats
def send_location( self, chat_id: Union[int, str], latitude: float, longitude: float, disable_notification: bool = None, reply_to_message_id: int = None, schedule_date: int = None, reply_markup: Union[ "pyrogram.InlineKeyboardMarkup", "pyrogram.ReplyKeyboardMarkup", "pyrogram.ReplyKeyboardRemove", "pyrogram.ForceReply" ] = None ) -> "pyrogram.Message": """Send points on the map. Parameters: chat_id (``int`` | ``str``): Unique identifier (int) or username (str) of the target chat. For your personal cloud (Saved Messages) you can simply use "me" or "self". For a contact that exists in your Telegram address book you can use his phone number (str). latitude (``float``): Latitude of the location. longitude (``float``): Longitude of the location. disable_notification (``bool``, *optional*): Sends the message silently. Users will receive a notification with no sound. reply_to_message_id (``int``, *optional*): If the message is a reply, ID of the original message schedule_date (``int``, *optional*): Date when the message will be automatically sent. Unix time. reply_markup (:obj:`InlineKeyboardMarkup` | :obj:`ReplyKeyboardMarkup` | :obj:`ReplyKeyboardRemove` | :obj:`ForceReply`, *optional*): Additional interface options. An object for an inline keyboard, custom reply keyboard, instructions to remove reply keyboard or to force a reply from the user. Returns: :obj:`Message`: On success, the sent location message is returned. Example: .. code-block:: python app.send_location("me", 51.500729, -0.124583) """ r = self.send( functions.messages.SendMedia( peer=self.resolve_peer(chat_id), media=types.InputMediaGeoPoint( geo_point=types.InputGeoPoint( lat=latitude, long=longitude ) ), message="", silent=disable_notification or None, reply_to_msg_id=reply_to_message_id, random_id=self.rnd_id(), schedule_date=schedule_date, reply_markup=reply_markup.write() if reply_markup else None ) ) for i in r.updates: if isinstance(i, (types.UpdateNewMessage, types.UpdateNewChannelMessage, types.UpdateNewScheduledMessage)): return pyrogram.Message._parse( self, i.message, {i.id: i for i in r.users}, {i.id: i for i in r.chats}, is_scheduled=isinstance(i, types.UpdateNewScheduledMessage) )
def send_venue( self, chat_id: Union[int, str], latitude: float, longitude: float, title: str, address: str, foursquare_id: str = "", foursquare_type: str = "", disable_notification: bool = None, reply_to_message_id: int = None, schedule_date: int = None, reply_markup: Union["pyrogram.InlineKeyboardMarkup", "pyrogram.ReplyKeyboardMarkup", "pyrogram.ReplyKeyboardRemove", "pyrogram.ForceReply"] = None ) -> "pyrogram.Message": """Send information about a venue. Parameters: chat_id (``int`` | ``str``): Unique identifier (int) or username (str) of the target chat. For your personal cloud (Saved Messages) you can simply use "me" or "self". For a contact that exists in your Telegram address book you can use his phone number (str). latitude (``float``): Latitude of the venue. longitude (``float``): Longitude of the venue. title (``str``): Name of the venue. address (``str``): Address of the venue. foursquare_id (``str``, *optional*): Foursquare identifier of the venue. foursquare_type (``str``, *optional*): Foursquare type of the venue, if known. (For example, "arts_entertainment/default", "arts_entertainment/aquarium" or "food/icecream".) disable_notification (``bool``, *optional*): Sends the message silently. Users will receive a notification with no sound. reply_to_message_id (``int``, *optional*): If the message is a reply, ID of the original message schedule_date (``int``, *optional*): Date when the message will be automatically sent. Unix time. reply_markup (:obj:`InlineKeyboardMarkup` | :obj:`ReplyKeyboardMarkup` | :obj:`ReplyKeyboardRemove` | :obj:`ForceReply`, *optional*): Additional interface options. An object for an inline keyboard, custom reply keyboard, instructions to remove reply keyboard or to force a reply from the user. Returns: :obj:`Message`: On success, the sent venue message is returned. Example: .. code-block:: python app.send_venue( "me", 51.500729, -0.124583, "Elizabeth Tower", "Westminster, London SW1A 0AA, UK") """ r = self.send( functions.messages.SendMedia( peer=self.resolve_peer(chat_id), media=types.InputMediaVenue(geo_point=types.InputGeoPoint( lat=latitude, long=longitude), title=title, address=address, provider="", venue_id=foursquare_id, venue_type=foursquare_type), message="", silent=disable_notification or None, reply_to_msg_id=reply_to_message_id, random_id=self.rnd_id(), schedule_date=schedule_date, reply_markup=reply_markup.write() if reply_markup else None)) for i in r.updates: if isinstance( i, (types.UpdateNewMessage, types.UpdateNewChannelMessage, types.UpdateNewScheduledMessage)): return pyrogram.Message._parse( self, i.message, {i.id: i for i in r.users}, {i.id: i for i in r.chats}, is_scheduled=isinstance(i, types.UpdateNewScheduledMessage))
def send_venue(self, chat_id: int or str, latitude: float, longitude: float, title: str, address: str, foursquare_id: str = "", foursquare_type: str = "", disable_notification: bool = None, reply_to_message_id: int = None, reply_markup=None): """Use this method to send information about a venue. Args: chat_id (``int`` | ``str``): Unique identifier (int) or username (str) of the target chat. For your personal cloud (Saved Messages) you can simply use "me" or "self". For a contact that exists in your Telegram address book you can use his phone number (str). latitude (``float``): Latitude of the venue. longitude (``float``): Longitude of the venue. title (``str``): Name of the venue. address (``str``): Address of the venue. foursquare_id (``str``, *optional*): Foursquare identifier of the venue. foursquare_type (``str``, *optional*): Foursquare type of the venue, if known. (For example, "arts_entertainment/default", "arts_entertainment/aquarium" or "food/icecream".) disable_notification (``bool``, *optional*): Sends the message silently. Users will receive a notification with no sound. reply_to_message_id (``int``, *optional*): If the message is a reply, ID of the original message reply_markup (:obj:`InlineKeyboardMarkup` | :obj:`ReplyKeyboardMarkup` | :obj:`ReplyKeyboardRemove` | :obj:`ForceReply`, *optional*): Additional interface options. An object for an inline keyboard, custom reply keyboard, instructions to remove reply keyboard or to force a reply from the user. Returns: On success, the sent :obj:`Message <pyrogram.Message>` is returned. Raises: :class:`Error <pyrogram.Error>` in case of a Telegram RPC error. """ r = self.send( functions.messages.SendMedia( peer=self.resolve_peer(chat_id), media=types.InputMediaVenue( geo_point=types.InputGeoPoint( lat=latitude, long=longitude ), title=title, address=address, provider="", venue_id=foursquare_id, venue_type=foursquare_type ), message="", silent=disable_notification or None, reply_to_msg_id=reply_to_message_id, random_id=self.rnd_id(), reply_markup=reply_markup.write() if reply_markup else None ) ) for i in r.updates: if isinstance(i, (types.UpdateNewMessage, types.UpdateNewChannelMessage)): return utils.parse_messages( self, i.message, {i.id: i for i in r.users}, {i.id: i for i in r.chats} )