Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
from . import fields
from .user import User
from ..utils import helper, markdown
class MessageEntity(base.TelegramObject):
"""
This object represents one special entity in a text message. For example, hashtags, usernames, URLs, etc.
https://core.telegram.org/bots/api#messageentity
"""
type: base.String = fields.Field()
offset: base.Integer = fields.Field()
length: base.Integer = fields.Field()
url: base.String = fields.Field()
user: User = fields.Field(base=User)
def get_text(self, text):
"""
Get value of entity
:param text: full text
:return: part of text
"""
if sys.maxunicode == 0xFFFF:
return text[self.offset : self.offset + self.length]
if not isinstance(text, bytes):
entity_text = text.encode("utf-16-le")
else:
entity_text = text
from . import base
from . import fields
from .shipping_address import ShippingAddress
class OrderInfo(base.TelegramObject):
"""
This object represents information about an order.
https://core.telegram.org/bots/api#orderinfo
"""
name: base.String = fields.Field()
phone_number: base.String = fields.Field()
email: base.String = fields.Field()
shipping_address: ShippingAddress = fields.Field(base=ShippingAddress)
from . import base
from . import fields
class LabeledPrice(base.TelegramObject):
"""
This object represents a portion of the price for goods or services.
https://core.telegram.org/bots/api#labeledprice
"""
label: base.String = fields.Field()
amount: base.Integer = fields.Field()
def __init__(self, label: base.String, amount: base.Integer):
super(LabeledPrice, self).__init__(label=label, amount=amount)
import typing
from . import base
from . import fields
from .labeled_price import LabeledPrice
class ShippingOption(base.TelegramObject):
"""
This object represents one shipping option.
https://core.telegram.org/bots/api#shippingoption
"""
id: base.String = fields.Field()
title: base.String = fields.Field()
prices: typing.List[LabeledPrice] = fields.ListField(base=LabeledPrice)
def __init__(self, id: base.String, title: base.String, prices: typing.List[LabeledPrice] = None):
if prices is None:
prices = []
super(ShippingOption, self).__init__(id=id, title=title, prices=prices)
def add(self, price: LabeledPrice):
"""
Add price
:param price:
:return:
"""
self.prices.append(price)
def __init__(self, source: base.String, type: base.String, field_name: base.String,
data_hash: base.String, message: base.String):
super(PassportElementErrorDataField, self).__init__(source=source, type=type, field_name=field_name,
data_hash=data_hash, message=message)
class PassportElementErrorFile(PassportElementError):
"""
Represents an issue with a document scan.
The error is considered resolved when the file with the document scan changes.
https://core.telegram.org/bots/api#passportelementerrorfile
"""
file_hash: base.String = fields.Field()
def __init__(self, source: base.String, type: base.String, file_hash: base.String, message: base.String):
super(PassportElementErrorFile, self).__init__(source=source, type=type, file_hash=file_hash,
message=message)
class PassportElementErrorFiles(PassportElementError):
"""
Represents an issue with a list of scans.
The error is considered resolved when the list of files containing the scans changes.
https://core.telegram.org/bots/api#passportelementerrorfiles
"""
file_hashes: typing.List[base.String] = fields.ListField()
from __future__ import annotations
from aiohttp import web
from . import base
from . import fields
class AuthWidgetData(base.TelegramObject):
id: base.Integer = fields.Field()
first_name: base.String = fields.Field()
last_name: base.String = fields.Field()
username: base.String = fields.Field()
photo_url: base.String = fields.Field()
auth_date: base.String = fields.DateTimeField()
hash: base.String = fields.Field()
@classmethod
def parse(cls, request: web.Request) -> AuthWidgetData:
"""
Parse request as Telegram auth widget data.
:param request:
:return: :obj:`AuthWidgetData`
:raise: :obj:`aiohttp.web.HTTPBadRequest`
"""
try:
query = dict(request.query)
query['id'] = int(query['id'])
query['auth_date'] = int(query['auth_date'])
widget = AuthWidgetData(**query)
from . import base
from . import fields
class LoginUrl(base.TelegramObject):
"""
This object represents a parameter of the inline keyboard button used to automatically authorize a user.
Serves as a great replacement for the Telegram Login Widget when the user is coming from Telegram.
All the user needs to do is tap/click a button and confirm that they want to log in.
https://core.telegram.org/bots/api#loginurl
"""
url: base.String = fields.Field()
forward_text: base.String = fields.Field()
bot_username: base.String = fields.Field()
request_write_access: base.Boolean = fields.Field()
def __init__(self,
url: base.String,
forward_text: base.String = None,
bot_username: base.String = None,
request_write_access: base.Boolean = None,
**kwargs):
super(LoginUrl, self).__init__(
url=url,
forward_text=forward_text,
bot_username=bot_username,
request_write_access=request_write_access,
**kwargs
import os
import pathlib
from . import base
from . import fields
class ChatPhoto(base.TelegramObject):
"""
This object represents a chat photo.
https://core.telegram.org/bots/api#chatphoto
"""
small_file_id: base.String = fields.Field()
big_file_id: base.String = fields.Field()
async def download_small(self, destination=None, timeout=30, chunk_size=65536, seek=True, make_dirs=True):
"""
Download file
:param destination: filename or instance of :class:`io.IOBase`. For e. g. :class:`io.BytesIO`
:param timeout: Integer
:param chunk_size: Integer
:param seek: Boolean - go to start of file when downloading is finished.
:param make_dirs: Make dirs if not exist
:return: destination
"""
file = await self.get_small_file()
is_path = True
if destination is None:
import typing
from . import base
from . import fields
from .sticker import Sticker
class StickerSet(base.TelegramObject):
"""
This object represents a sticker set.
https://core.telegram.org/bots/api#stickerset
"""
name: base.String = fields.Field()
title: base.String = fields.Field()
is_animated: base.Boolean = fields.Field()
contains_masks: base.Boolean = fields.Field()
stickers: typing.List[Sticker] = fields.ListField(base=Sticker)
from . import base
from . import fields
from .shipping_address import ShippingAddress
from .user import User
class ShippingQuery(base.TelegramObject):
"""
This object contains information about an incoming shipping query.
https://core.telegram.org/bots/api#shippingquery
"""
id: base.String = fields.Field()
from_user: User = fields.Field(alias='from', base=User)
invoice_payload: base.String = fields.Field()
shipping_address: ShippingAddress = fields.Field(base=ShippingAddress)
def __hash__(self):
return self.id
def __eq__(self, other):
if isinstance(other, type(self)):
return other.id == self.id
return self.id == other