mirror of
https://github.com/eternnoir/pyTelegramBotAPI.git
synced 2023-08-10 21:12:57 +03:00
Merge remote-tracking branch 'refs/remotes/eternnoir/feature-BotAPIV3' into feature-BotAPIV3
This commit is contained in:
commit
f8fed5c942
@ -544,6 +544,19 @@ def get_game_high_scores(token, user_id, chat_id=None, message_id=None, inline_m
|
||||
payload['inline_message_id'] = inline_message_id
|
||||
return _make_request(token, method_url, params=payload)
|
||||
|
||||
# Payments (https://core.telegram.org/bots/api#payments)
|
||||
|
||||
def send_invoice():
|
||||
# TODO
|
||||
pass
|
||||
|
||||
def answer_shippingQuery():
|
||||
# TODO
|
||||
pass
|
||||
|
||||
def answer_pre_checkout_query():
|
||||
# TODO
|
||||
pass
|
||||
|
||||
# InlineQuery
|
||||
|
||||
|
190
telebot/types.py
190
telebot/types.py
@ -101,6 +101,8 @@ class Update(JsonDeserializable):
|
||||
inline_query = None
|
||||
chosen_inline_result = None
|
||||
callback_query = None
|
||||
shipping_query = None
|
||||
pre_checkout_query = None
|
||||
if 'message' in obj:
|
||||
message = Message.de_json(obj['message'])
|
||||
if 'edited_message' in obj:
|
||||
@ -115,11 +117,15 @@ class Update(JsonDeserializable):
|
||||
chosen_inline_result = ChosenInlineResult.de_json(obj['chosen_inline_result'])
|
||||
if 'callback_query' in obj:
|
||||
callback_query = CallbackQuery.de_json(obj['callback_query'])
|
||||
if 'shipping_query' in obj:
|
||||
shipping_query = ShippingQuery.de_json(obj['shipping_query'])
|
||||
if 'pre_checkout_query' in obj:
|
||||
pre_checkout_query = PreCheckoutQuery.de_json(obj['pre_checkout_query'])
|
||||
return cls(update_id, message, edited_message, channel_post, edited_channel_post, inline_query,
|
||||
chosen_inline_result, callback_query)
|
||||
chosen_inline_result, callback_query, shipping_query, pre_checkout_query)
|
||||
|
||||
def __init__(self, update_id, message, edited_message, channel_post, edited_channel_post, inline_query,
|
||||
chosen_inline_result, callback_query):
|
||||
chosen_inline_result, callback_query, shipping_query, pre_checkout_query):
|
||||
self.update_id = update_id
|
||||
self.edited_message = edited_message
|
||||
self.message = message
|
||||
@ -129,6 +135,8 @@ class Update(JsonDeserializable):
|
||||
self.inline_query = inline_query
|
||||
self.chosen_inline_result = chosen_inline_result
|
||||
self.callback_query = callback_query
|
||||
self.shipping_query = shipping_query
|
||||
self.pre_checkout_query = pre_checkout_query
|
||||
|
||||
|
||||
class WebhookInfo(JsonDeserializable):
|
||||
@ -148,9 +156,11 @@ class WebhookInfo(JsonDeserializable):
|
||||
max_connections = obj['max_connections']
|
||||
if 'allowed_updates' in obj:
|
||||
allowed_updates = obj['allowed_updates']
|
||||
return cls(url, has_custom_certificate, pending_update_count, last_error_date, last_error_message, max_connections, allowed_updates)
|
||||
return cls(url, has_custom_certificate, pending_update_count, last_error_date, last_error_message,
|
||||
max_connections, allowed_updates)
|
||||
|
||||
def __init__(self, url, has_custom_certificate, pending_update_count, last_error_date, last_error_message, max_connections, allowed_updates):
|
||||
def __init__(self, url, has_custom_certificate, pending_update_count, last_error_date, last_error_message,
|
||||
max_connections, allowed_updates):
|
||||
self.url = url
|
||||
self.has_custom_certificate = has_custom_certificate
|
||||
self.pending_update_count = pending_update_count
|
||||
@ -307,6 +317,12 @@ class Message(JsonDeserializable):
|
||||
opts['migrate_from_chat_id'] = obj['migrate_from_chat_id']
|
||||
if 'pinned_message' in obj:
|
||||
opts['pinned_message'] = Message.de_json(obj['pinned_message'])
|
||||
if 'invoice' in obj:
|
||||
opts['invoice'] = Invoice.de_json(obj['invoice'])
|
||||
content_type = 'invoice'
|
||||
if 'successful_payment' in obj:
|
||||
opts['successful_payment'] = SuccessfulPayment.de_json(obj['successful_payment'])
|
||||
content_type = 'successful_payment'
|
||||
return cls(message_id, from_user, date, chat, content_type, opts)
|
||||
|
||||
@classmethod
|
||||
@ -365,6 +381,8 @@ class Message(JsonDeserializable):
|
||||
self.migrate_to_chat_id = None
|
||||
self.migrate_from_chat_id = None
|
||||
self.pinned_message = None
|
||||
self.invoice = None
|
||||
self.successful_payment = None
|
||||
for key in options:
|
||||
setattr(self, key, options[key])
|
||||
|
||||
@ -1608,3 +1626,167 @@ class GameHighScore(JsonDeserializable):
|
||||
self.position = position
|
||||
self.user = user
|
||||
self.score = score
|
||||
|
||||
|
||||
# Payments
|
||||
|
||||
class LabeledPrice(JsonSerializable):
|
||||
def __init__(self, label, amount):
|
||||
self.label = label
|
||||
self.amount = amount
|
||||
|
||||
def to_json(self):
|
||||
return json.dumps(self.to_dic())
|
||||
|
||||
def to_dic(self):
|
||||
return {'label': self.label, 'amount': self.amount}
|
||||
|
||||
|
||||
class Invoice(JsonDeserializable):
|
||||
@classmethod
|
||||
def de_json(cls, json_string):
|
||||
obj = cls.check_json(json_string)
|
||||
title = obj['title']
|
||||
description = obj['description']
|
||||
start_parameter = obj['start_parameter']
|
||||
currency = obj['currency']
|
||||
total_amount = obj['total_amount']
|
||||
return cls(title, description, start_parameter, currency, total_amount)
|
||||
|
||||
def __init__(self, title, description, start_parameter, currency, total_amount):
|
||||
self.title = title
|
||||
self.description = description
|
||||
self.start_parameter = start_parameter
|
||||
self.currency = currency
|
||||
self.total_amount = total_amount
|
||||
|
||||
|
||||
class ShippingAddress(JsonDeserializable):
|
||||
@classmethod
|
||||
def de_json(cls, json_string):
|
||||
obj = cls.check_json(json_string)
|
||||
country_code = obj['country_code']
|
||||
state = obj['state']
|
||||
city = obj['city']
|
||||
street_line1 = obj['street_line1']
|
||||
street_line2 = obj['street_line2']
|
||||
post_code = obj['post_code']
|
||||
return cls(country_code, state, city, street_line1, street_line2, post_code)
|
||||
|
||||
def __init__(self, country_code, state, city, street_line1, street_line2, post_code):
|
||||
self.country_code = country_code
|
||||
self.state = state
|
||||
self.city = city
|
||||
self.street_line1 = street_line1
|
||||
self.street_line2 = street_line2
|
||||
self.post_code = post_code
|
||||
|
||||
|
||||
class OrderInfo(JsonDeserializable):
|
||||
@classmethod
|
||||
def de_json(cls, json_string):
|
||||
obj = cls.check_json(json_string)
|
||||
name = obj.get('name')
|
||||
phone_number = obj.get('phone_number')
|
||||
email = obj.get('email')
|
||||
shipping_address = None
|
||||
if 'shipping_address' in obj:
|
||||
shipping_address = ShippingAddress.de_json(obj['shipping_address'])
|
||||
return cls(name, phone_number, email, shipping_address)
|
||||
|
||||
def __init__(self, name, phone_number, email, shipping_address):
|
||||
self.name = name
|
||||
self.phone_number = phone_number
|
||||
self.email = email
|
||||
self.shipping_address = shipping_address
|
||||
|
||||
|
||||
class ShippingOption(JsonSerializable):
|
||||
def __init__(self, id, title):
|
||||
self.id = id
|
||||
self.title = title
|
||||
self.prices = []
|
||||
|
||||
def add_price(self, *args):
|
||||
"""
|
||||
Add LabeledPrice to ShippingOption
|
||||
:param args: LabeledPrices
|
||||
"""
|
||||
for price in args:
|
||||
self.prices.append(price)
|
||||
|
||||
def to_json(self):
|
||||
price_list = []
|
||||
for p in self.prices:
|
||||
price_list.append(p.to_dic())
|
||||
json_dict = {'id': self.id, 'title': self.title, 'prices': price_list}
|
||||
return json_dict
|
||||
|
||||
|
||||
class SuccessfulPayment(JsonDeserializable):
|
||||
@classmethod
|
||||
def de_json(cls, json_string):
|
||||
obj = cls.check_json(json_string)
|
||||
currency = obj['currency']
|
||||
total_amount = obj['total_amount']
|
||||
invoice_payload = obj['invoice_payload']
|
||||
shipping_option_id = obj.get('shipping_option_id')
|
||||
order_info = None
|
||||
if 'order_info' in obj:
|
||||
order_info = OrderInfo.de_json(obj['order_info'])
|
||||
telegram_payment_charge_id = obj['telegram_payment_charge_id']
|
||||
provider_payment_charge_id = obj['provider_payment_charge_id']
|
||||
return cls(currency, total_amount, invoice_payload, shipping_option_id, order_info,
|
||||
telegram_payment_charge_id, provider_payment_charge_id)
|
||||
|
||||
def __init__(self, currency, total_amount, invoice_payload, shipping_option_id, order_info,
|
||||
telegram_payment_charge_id, provider_payment_charge_id):
|
||||
self.currency = currency
|
||||
self.total_amount = total_amount
|
||||
self.invoice_payload = invoice_payload
|
||||
self.shipping_option_id = shipping_option_id
|
||||
self.order_info = order_info
|
||||
self.telegram_payment_charge_id = telegram_payment_charge_id
|
||||
self.provider_payment_charge_id = provider_payment_charge_id
|
||||
|
||||
|
||||
class ShippingQuery(JsonDeserializable):
|
||||
@classmethod
|
||||
def de_json(cls, json_string):
|
||||
obj = cls.check_json(json_string)
|
||||
id = obj['id']
|
||||
from_user = User.de_json(obj['from'])
|
||||
invoice_payload = obj['invoice_payload']
|
||||
shipping_address = ShippingAddress.de_json(obj['shipping_address'])
|
||||
return cls(id, from_user, invoice_payload, shipping_address)
|
||||
|
||||
def __init__(self, id, from_user, invoice_payload, shipping_address):
|
||||
self.id = id
|
||||
self.from_user = from_user
|
||||
self.invoice_payload = invoice_payload
|
||||
self.shipping_address = shipping_address
|
||||
|
||||
|
||||
class PreCheckoutQuery(JsonDeserializable):
|
||||
@classmethod
|
||||
def de_json(cls, json_string):
|
||||
obj = cls.check_json(json_string)
|
||||
id = obj['id']
|
||||
from_user = User.de_json(obj['from'])
|
||||
currency = obj['currency']
|
||||
total_amount = obj['total_amount']
|
||||
invoice_payload = obj['invoice_payload']
|
||||
shipping_option_id = obj.get('shipping_option_id')
|
||||
order_info = None
|
||||
if 'order_info' in obj:
|
||||
order_info = OrderInfo.de_json(obj['order_info'])
|
||||
return cls(id, from_user, currency, total_amount, invoice_payload, shipping_option_id, order_info)
|
||||
|
||||
def __init__(self, id, from_user, currency, total_amount, invoice_payload, shipping_option_id, order_info):
|
||||
self.id = id
|
||||
self.from_user = from_user
|
||||
self.currency = currency
|
||||
self.total_amount = total_amount
|
||||
self.invoice_payload = invoice_payload
|
||||
self.shipping_option_id = shipping_option_id
|
||||
self.order_info = order_info
|
||||
|
@ -403,3 +403,9 @@ class TestTeleBot:
|
||||
def test_not_string(self):
|
||||
i1 = 10
|
||||
assert not util.is_string(i1)
|
||||
|
||||
def test_send_video_note(self):
|
||||
file_data = open('./test_data/test_video.mp4', 'rb')
|
||||
tb = telebot.TeleBot(TOKEN)
|
||||
ret_msg = tb.send_video_note(CHAT_ID, file_data)
|
||||
assert ret_msg.message_id
|
||||
|
Loading…
Reference in New Issue
Block a user