1
0
mirror of https://github.com/eternnoir/pyTelegramBotAPI.git synced 2023-08-10 21:12:57 +03:00

Renaming back pytelegrambotapi module to telebot

This commit is contained in:
Waffle 2018-04-28 13:50:59 +03:00
parent 183230e927
commit 3ba9799b98
18 changed files with 102 additions and 102 deletions

View File

@ -30,10 +30,10 @@
# Steps 1 to 4 will have to be implemented in a web server, using a language such as PHP, Python, C# or Java. These # Steps 1 to 4 will have to be implemented in a web server, using a language such as PHP, Python, C# or Java. These
# steps are not shown here. Only steps 5 to 7 are illustrated, some in pseudo-code, with this example. # steps are not shown here. Only steps 5 to 7 are illustrated, some in pseudo-code, with this example.
import pytelegrambotapi import telebot
import time import time
bot = pytelegrambotapi.TeleBot('TOKEN') bot = telebot.TeleBot('TOKEN')
def extract_unique_code(text): def extract_unique_code(text):
# Extracts the unique_code from the sent /start command. # Extracts the unique_code from the sent /start command.

View File

@ -2,8 +2,8 @@
This is a detailed example using almost every command of the API This is a detailed example using almost every command of the API
""" """
import pytelegrambotapi import telebot
from pytelegrambotapi import types from telebot import types
import time import time
TOKEN = '<token_string>' TOKEN = '<token_string>'
@ -48,7 +48,7 @@ def listener(messages):
print str(m.chat.first_name) + " [" + str(m.chat.id) + "]: " + m.text print str(m.chat.first_name) + " [" + str(m.chat.id) + "]: " + m.text
bot = pytelegrambotapi.TeleBot(TOKEN) bot = telebot.TeleBot(TOKEN)
bot.set_update_listener(listener) # register listener bot.set_update_listener(listener) # register listener

View File

@ -1,11 +1,11 @@
# This is a simple echo bot using the decorator mechanism. # This is a simple echo bot using the decorator mechanism.
# It echoes any incoming text messages. # It echoes any incoming text messages.
import pytelegrambotapi import telebot
API_TOKEN = '<api_token>' API_TOKEN = '<api_token>'
bot = pytelegrambotapi.TeleBot(API_TOKEN) bot = telebot.TeleBot(API_TOKEN)
# Handle '/start' and '/help' # Handle '/start' and '/help'
@bot.message_handler(commands=['help', 'start']) @bot.message_handler(commands=['help', 'start'])

View File

@ -4,12 +4,12 @@ This Example will show you how to use register_next_step handler.
""" """
import time import time
import pytelegrambotapi import telebot
from pytelegrambotapi import types from telebot import types
API_TOKEN = '<api_token>' API_TOKEN = '<api_token>'
bot = pytelegrambotapi.TeleBot(API_TOKEN) bot = telebot.TeleBot(API_TOKEN)
user_dict = {} user_dict = {}

View File

@ -3,7 +3,7 @@
# and goes by the name 'TeleBot (@pyTeleBot)'. Join our group to talk to him! # and goes by the name 'TeleBot (@pyTeleBot)'. Join our group to talk to him!
# WARNING: Tested with Python 2.7 # WARNING: Tested with Python 2.7
import pytelegrambotapi import telebot
import os import os
text_messages = { text_messages = {
@ -30,7 +30,7 @@ text_messages = {
if "TELEBOT_BOT_TOKEN" not in os.environ or "GROUP_CHAT_ID" not in os.environ: if "TELEBOT_BOT_TOKEN" not in os.environ or "GROUP_CHAT_ID" not in os.environ:
raise AssertionError("Please configure TELEBOT_BOT_TOKEN and GROUP_CHAT_ID as environment variables") raise AssertionError("Please configure TELEBOT_BOT_TOKEN and GROUP_CHAT_ID as environment variables")
bot = pytelegrambotapi.AsyncTeleBot(os.environ["TELEBOT_BOT_TOKEN"]) bot = telebot.AsyncTeleBot(os.environ["TELEBOT_BOT_TOKEN"])
GROUP_CHAT_ID = int(os.environ["GROUP_CHAT_ID"]) GROUP_CHAT_ID = int(os.environ["GROUP_CHAT_ID"])
def is_api_group(chat_id): def is_api_group(chat_id):

View File

@ -9,7 +9,7 @@ import ssl
from aiohttp import web from aiohttp import web
import pytelegrambotapi import telebot
API_TOKEN = '<api_token>' API_TOKEN = '<api_token>'
@ -33,10 +33,10 @@ WEBHOOK_URL_BASE = "https://{}:{}".format(WEBHOOK_HOST, WEBHOOK_PORT)
WEBHOOK_URL_PATH = "/{}/".format(API_TOKEN) WEBHOOK_URL_PATH = "/{}/".format(API_TOKEN)
logger = pytelegrambotapi.logger logger = telebot.logger
pytelegrambotapi.logger.setLevel(logging.INFO) telebot.logger.setLevel(logging.INFO)
bot = pytelegrambotapi.TeleBot(API_TOKEN) bot = telebot.TeleBot(API_TOKEN)
app = web.Application() app = web.Application()
@ -45,7 +45,7 @@ app = web.Application()
async def handle(request): async def handle(request):
if request.match_info.get('token') == bot.token: if request.match_info.get('token') == bot.token:
request_body_dict = await request.json() request_body_dict = await request.json()
update = pytelegrambotapi.types.Update.de_json(request_body_dict) update = telebot.types.Update.de_json(request_body_dict)
bot.process_new_updates([update]) bot.process_new_updates([update])
return web.Response() return web.Response()
else: else:

View File

@ -5,7 +5,7 @@
# It echoes any incoming text messages and does not use the polling method. # It echoes any incoming text messages and does not use the polling method.
import cherrypy import cherrypy
import pytelegrambotapi import telebot
import logging import logging
@ -30,10 +30,10 @@ WEBHOOK_URL_BASE = "https://%s:%s" % (WEBHOOK_HOST, WEBHOOK_PORT)
WEBHOOK_URL_PATH = "/%s/" % (API_TOKEN) WEBHOOK_URL_PATH = "/%s/" % (API_TOKEN)
logger = pytelegrambotapi.logger logger = telebot.logger
pytelegrambotapi.logger.setLevel(logging.INFO) telebot.logger.setLevel(logging.INFO)
bot = pytelegrambotapi.TeleBot(API_TOKEN) bot = telebot.TeleBot(API_TOKEN)
# WebhookServer, process webhook calls # WebhookServer, process webhook calls
@ -45,7 +45,7 @@ class WebhookServer(object):
cherrypy.request.headers['content-type'] == 'application/json': cherrypy.request.headers['content-type'] == 'application/json':
length = int(cherrypy.request.headers['content-length']) length = int(cherrypy.request.headers['content-length'])
json_string = cherrypy.request.body.read(length).decode("utf-8") json_string = cherrypy.request.body.read(length).decode("utf-8")
update = pytelegrambotapi.types.Update.de_json(json_string) update = telebot.types.Update.de_json(json_string)
bot.process_new_updates([update]) bot.process_new_updates([update])
return '' return ''
else: else:

View File

@ -6,7 +6,7 @@
import BaseHTTPServer import BaseHTTPServer
import ssl import ssl
import pytelegrambotapi import telebot
import logging import logging
@ -31,10 +31,10 @@ WEBHOOK_URL_BASE = "https://%s:%s" % (WEBHOOK_HOST, WEBHOOK_PORT)
WEBHOOK_URL_PATH = "/%s/" % (API_TOKEN) WEBHOOK_URL_PATH = "/%s/" % (API_TOKEN)
logger = pytelegrambotapi.logger logger = telebot.logger
pytelegrambotapi.logger.setLevel(logging.INFO) telebot.logger.setLevel(logging.INFO)
bot = pytelegrambotapi.TeleBot(API_TOKEN) bot = telebot.TeleBot(API_TOKEN)
# WebhookHandler, process webhook calls # WebhookHandler, process webhook calls
@ -59,7 +59,7 @@ class WebhookHandler(BaseHTTPServer.BaseHTTPRequestHandler):
self.send_response(200) self.send_response(200)
self.end_headers() self.end_headers()
update = pytelegrambotapi.types.Update.de_json(json_string) update = telebot.types.Update.de_json(json_string)
bot.process_new_messages([update.message]) bot.process_new_messages([update.message])
else: else:
self.send_error(403) self.send_error(403)

View File

@ -5,7 +5,7 @@
# It echoes any incoming text messages and does not use the polling method. # It echoes any incoming text messages and does not use the polling method.
import flask import flask
import pytelegrambotapi import telebot
import logging import logging
@ -30,10 +30,10 @@ WEBHOOK_URL_BASE = "https://%s:%s" % (WEBHOOK_HOST, WEBHOOK_PORT)
WEBHOOK_URL_PATH = "/%s/" % (API_TOKEN) WEBHOOK_URL_PATH = "/%s/" % (API_TOKEN)
logger = pytelegrambotapi.logger logger = telebot.logger
pytelegrambotapi.logger.setLevel(logging.INFO) telebot.logger.setLevel(logging.INFO)
bot = pytelegrambotapi.TeleBot(API_TOKEN) bot = telebot.TeleBot(API_TOKEN)
app = flask.Flask(__name__) app = flask.Flask(__name__)
@ -49,7 +49,7 @@ def index():
def webhook(): def webhook():
if flask.request.headers.get('content-type') == 'application/json': if flask.request.headers.get('content-type') == 'application/json':
json_string = flask.request.get_data().decode('utf-8') json_string = flask.request.get_data().decode('utf-8')
update = pytelegrambotapi.types.Update.de_json(json_string) update = telebot.types.Update.de_json(json_string)
bot.process_new_updates([update]) bot.process_new_updates([update])
return '' return ''
else: else:

View File

@ -1,10 +1,10 @@
import os import os
import pytelegrambotapi import telebot
from flask import Flask, request from flask import Flask, request
TOKEN = '<api_token>' TOKEN = '<api_token>'
bot = pytelegrambotapi.TeleBot(TOKEN) bot = telebot.TeleBot(TOKEN)
server = Flask(__name__) server = Flask(__name__)
@ -20,7 +20,7 @@ def echo_message(message):
@server.route('/' + TOKEN, methods=['POST']) @server.route('/' + TOKEN, methods=['POST'])
def getMessage(): def getMessage():
bot.process_new_updates([pytelegrambotapi.types.Update.de_json(request.stream.read().decode("utf-8"))]) bot.process_new_updates([telebot.types.Update.de_json(request.stream.read().decode("utf-8"))])
return "!", 200 return "!", 200

View File

@ -4,7 +4,7 @@
# This example shows webhook echo bot with Tornado web framework # This example shows webhook echo bot with Tornado web framework
# Documenation to Tornado: http://tornadoweb.org # Documenation to Tornado: http://tornadoweb.org
import pytelegrambotapi import telebot
import tornado.web import tornado.web
import tornado.ioloop import tornado.ioloop
import tornado.httpserver import tornado.httpserver
@ -27,7 +27,7 @@ WEBHOOK_URL_BASE = "https://{0}:{1}/{2}".format(WEBHOOK_HOST, str(WEBHOOK_PORT),
# When asked for "Common Name (e.g. server FQDN or YOUR name)" you should reply # When asked for "Common Name (e.g. server FQDN or YOUR name)" you should reply
# with the same value in you put in WEBHOOK_HOST # with the same value in you put in WEBHOOK_HOST
bot = pytelegrambotapi.TeleBot(API_TOKEN) bot = telebot.TeleBot(API_TOKEN)
class Root(tornado.web.RequestHandler): class Root(tornado.web.RequestHandler):
def get(self): def get(self):
@ -45,7 +45,7 @@ class webhook_serv(tornado.web.RequestHandler):
# length = int(self.request.headers['Content-Length']) # length = int(self.request.headers['Content-Length'])
json_data = self.request.body.decode("utf-8") json_data = self.request.body.decode("utf-8")
update = pytelegrambotapi.types.Update.de_json(json_data) update = telebot.types.Update.de_json(json_data)
bot.process_new_updates([update]) bot.process_new_updates([update])
self.write("") self.write("")
self.finish() self.finish()

View File

@ -13,7 +13,7 @@ setup(name='pyTelegramBotAPI',
author='eternnoir', author='eternnoir',
author_email='eternnoir@gmail.com', author_email='eternnoir@gmail.com',
url='https://github.com/eternnoir/pyTelegramBotAPI', url='https://github.com/eternnoir/pyTelegramBotAPI',
packages=['pytelegrambotapi'], packages=['telebot'],
license='GPL2', license='GPL2',
keywords='telegram bot api tools', keywords='telegram bot api tools',
install_requires=['requests', 'six'], install_requires=['requests', 'six'],

View File

@ -20,7 +20,7 @@ logger.addHandler(console_output_handler)
logger.setLevel(logging.ERROR) logger.setLevel(logging.ERROR)
from pytelegrambotapi import apihelper, types, util from telebot import apihelper, types, util
""" """
Module : telebot Module : telebot

View File

@ -13,11 +13,11 @@ try:
format_header_param = fields.format_header_param format_header_param = fields.format_header_param
except ImportError: except ImportError:
format_header_param = None format_header_param = None
import pytelegrambotapi import telebot
from pytelegrambotapi import types from telebot import types
from pytelegrambotapi import util from telebot import util
logger = pytelegrambotapi.logger logger = telebot.logger
proxy = None proxy = None
API_URL = "https://api.telegram.org/bot{0}/{1}" API_URL = "https://api.telegram.org/bot{0}/{1}"

View File

@ -7,7 +7,7 @@ except ImportError:
import six import six
from pytelegrambotapi import util from telebot import util
class JsonSerializable: class JsonSerializable:

View File

@ -7,9 +7,9 @@ import time
import pytest import pytest
import os import os
import pytelegrambotapi import telebot
from pytelegrambotapi import types from telebot import types
from pytelegrambotapi import util from telebot import util
should_skip = 'TOKEN' and 'CHAT_ID' not in os.environ should_skip = 'TOKEN' and 'CHAT_ID' not in os.environ
@ -29,11 +29,11 @@ class TestTeleBot:
def listener(messages): def listener(messages):
assert len(messages) == 100 assert len(messages) == 100
tb = pytelegrambotapi.TeleBot('') tb = telebot.TeleBot('')
tb.set_update_listener(listener) tb.set_update_listener(listener)
def test_message_handler(self): def test_message_handler(self):
tb = pytelegrambotapi.TeleBot('') tb = telebot.TeleBot('')
msg = self.create_text_message('/help') msg = self.create_text_message('/help')
@tb.message_handler(commands=['help', 'start']) @tb.message_handler(commands=['help', 'start'])
@ -45,7 +45,7 @@ class TestTeleBot:
assert msg.text == 'got' assert msg.text == 'got'
def test_message_handler_reg(self): def test_message_handler_reg(self):
bot = pytelegrambotapi.TeleBot('') bot = telebot.TeleBot('')
msg = self.create_text_message(r'https://web.telegram.org/') msg = self.create_text_message(r'https://web.telegram.org/')
@bot.message_handler(regexp='((https?):((//)|(\\\\))+([\w\d:#@%/;$()~_?\+-=\\\.&](#!)?)*)') @bot.message_handler(regexp='((https?):((//)|(\\\\))+([\w\d:#@%/;$()~_?\+-=\\\.&](#!)?)*)')
@ -57,7 +57,7 @@ class TestTeleBot:
assert msg.text == 'got' assert msg.text == 'got'
def test_message_handler_lambda(self): def test_message_handler_lambda(self):
bot = pytelegrambotapi.TeleBot('') bot = telebot.TeleBot('')
msg = self.create_text_message(r'lambda_text') msg = self.create_text_message(r'lambda_text')
@bot.message_handler(func=lambda message: r'lambda' in message.text) @bot.message_handler(func=lambda message: r'lambda' in message.text)
@ -69,7 +69,7 @@ class TestTeleBot:
assert msg.text == 'got' assert msg.text == 'got'
def test_message_handler_lambda_fail(self): def test_message_handler_lambda_fail(self):
bot = pytelegrambotapi.TeleBot('') bot = telebot.TeleBot('')
msg = self.create_text_message(r'text') msg = self.create_text_message(r'text')
@bot.message_handler(func=lambda message: r'lambda' in message.text) @bot.message_handler(func=lambda message: r'lambda' in message.text)
@ -81,7 +81,7 @@ class TestTeleBot:
assert not msg.text == 'got' assert not msg.text == 'got'
def test_message_handler_reg_fail(self): def test_message_handler_reg_fail(self):
bot = pytelegrambotapi.TeleBot('') bot = telebot.TeleBot('')
msg = self.create_text_message(r'web.telegram.org/') msg = self.create_text_message(r'web.telegram.org/')
@bot.message_handler(regexp='((https?):((//)|(\\\\))+([\w\d:#@%/;$()~_?\+-=\\\.&](#!)?)*)') @bot.message_handler(regexp='((https?):((//)|(\\\\))+([\w\d:#@%/;$()~_?\+-=\\\.&](#!)?)*)')
@ -93,7 +93,7 @@ class TestTeleBot:
assert not msg.text == 'got' assert not msg.text == 'got'
def test_send_message_with_markdown(self): def test_send_message_with_markdown(self):
tb = pytelegrambotapi.TeleBot(TOKEN) tb = telebot.TeleBot(TOKEN)
markdown = """ markdown = """
*bold text* *bold text*
_italic text_ _italic text_
@ -103,7 +103,7 @@ class TestTeleBot:
assert ret_msg.message_id assert ret_msg.message_id
def test_send_message_with_disable_notification(self): def test_send_message_with_disable_notification(self):
tb = pytelegrambotapi.TeleBot(TOKEN) tb = telebot.TeleBot(TOKEN)
markdown = """ markdown = """
*bold text* *bold text*
_italic text_ _italic text_
@ -114,7 +114,7 @@ class TestTeleBot:
def test_send_file(self): def test_send_file(self):
file_data = open('../examples/detailed_example/kitten.jpg', 'rb') file_data = open('../examples/detailed_example/kitten.jpg', 'rb')
tb = pytelegrambotapi.TeleBot(TOKEN) tb = telebot.TeleBot(TOKEN)
ret_msg = tb.send_document(CHAT_ID, file_data) ret_msg = tb.send_document(CHAT_ID, file_data)
assert ret_msg.message_id assert ret_msg.message_id
@ -123,7 +123,7 @@ class TestTeleBot:
def test_send_file_dis_noti(self): def test_send_file_dis_noti(self):
file_data = open('../examples/detailed_example/kitten.jpg', 'rb') file_data = open('../examples/detailed_example/kitten.jpg', 'rb')
tb = pytelegrambotapi.TeleBot(TOKEN) tb = telebot.TeleBot(TOKEN)
ret_msg = tb.send_document(CHAT_ID, file_data, disable_notification=True) ret_msg = tb.send_document(CHAT_ID, file_data, disable_notification=True)
assert ret_msg.message_id assert ret_msg.message_id
@ -132,7 +132,7 @@ class TestTeleBot:
def test_send_file_caption(self): def test_send_file_caption(self):
file_data = open('../examples/detailed_example/kitten.jpg', 'rb') file_data = open('../examples/detailed_example/kitten.jpg', 'rb')
tb = pytelegrambotapi.TeleBot(TOKEN) tb = telebot.TeleBot(TOKEN)
ret_msg = tb.send_document(CHAT_ID, file_data, caption="Test") ret_msg = tb.send_document(CHAT_ID, file_data, caption="Test")
assert ret_msg.message_id assert ret_msg.message_id
@ -141,30 +141,30 @@ class TestTeleBot:
def test_send_video(self): def test_send_video(self):
file_data = open('./test_data/test_video.mp4', 'rb') file_data = open('./test_data/test_video.mp4', 'rb')
tb = pytelegrambotapi.TeleBot(TOKEN) tb = telebot.TeleBot(TOKEN)
ret_msg = tb.send_video(CHAT_ID, file_data) ret_msg = tb.send_video(CHAT_ID, file_data)
assert ret_msg.message_id assert ret_msg.message_id
def test_send_video_dis_noti(self): def test_send_video_dis_noti(self):
file_data = open('./test_data/test_video.mp4', 'rb') file_data = open('./test_data/test_video.mp4', 'rb')
tb = pytelegrambotapi.TeleBot(TOKEN) tb = telebot.TeleBot(TOKEN)
ret_msg = tb.send_video(CHAT_ID, file_data, disable_notification=True) ret_msg = tb.send_video(CHAT_ID, file_data, disable_notification=True)
assert ret_msg.message_id assert ret_msg.message_id
def test_send_video_more_params(self): def test_send_video_more_params(self):
file_data = open('./test_data/test_video.mp4', 'rb') file_data = open('./test_data/test_video.mp4', 'rb')
tb = pytelegrambotapi.TeleBot(TOKEN) tb = telebot.TeleBot(TOKEN)
ret_msg = tb.send_video(CHAT_ID, file_data, 1) ret_msg = tb.send_video(CHAT_ID, file_data, 1)
assert ret_msg.message_id assert ret_msg.message_id
def test_send_video_more_params_dis_noti(self): def test_send_video_more_params_dis_noti(self):
file_data = open('./test_data/test_video.mp4', 'rb') file_data = open('./test_data/test_video.mp4', 'rb')
tb = pytelegrambotapi.TeleBot(TOKEN) tb = telebot.TeleBot(TOKEN)
ret_msg = tb.send_video(CHAT_ID, file_data, 1, disable_notification=True) ret_msg = tb.send_video(CHAT_ID, file_data, 1, disable_notification=True)
assert ret_msg.message_id assert ret_msg.message_id
def test_send_file_exception(self): def test_send_file_exception(self):
tb = pytelegrambotapi.TeleBot(TOKEN) tb = telebot.TeleBot(TOKEN)
try: try:
tb.send_document(CHAT_ID, None) tb.send_document(CHAT_ID, None)
assert False assert False
@ -174,7 +174,7 @@ class TestTeleBot:
def test_send_photo(self): def test_send_photo(self):
file_data = open('../examples/detailed_example/kitten.jpg', 'rb') file_data = open('../examples/detailed_example/kitten.jpg', 'rb')
tb = pytelegrambotapi.TeleBot(TOKEN) tb = telebot.TeleBot(TOKEN)
ret_msg = tb.send_photo(CHAT_ID, file_data) ret_msg = tb.send_photo(CHAT_ID, file_data)
assert ret_msg.message_id assert ret_msg.message_id
@ -183,7 +183,7 @@ class TestTeleBot:
def test_send_photo_dis_noti(self): def test_send_photo_dis_noti(self):
file_data = open('../examples/detailed_example/kitten.jpg', 'rb') file_data = open('../examples/detailed_example/kitten.jpg', 'rb')
tb = pytelegrambotapi.TeleBot(TOKEN) tb = telebot.TeleBot(TOKEN)
ret_msg = tb.send_photo(CHAT_ID, file_data) ret_msg = tb.send_photo(CHAT_ID, file_data)
assert ret_msg.message_id assert ret_msg.message_id
@ -192,7 +192,7 @@ class TestTeleBot:
def test_send_audio(self): def test_send_audio(self):
file_data = open('./test_data/record.mp3', 'rb') file_data = open('./test_data/record.mp3', 'rb')
tb = pytelegrambotapi.TeleBot(TOKEN) tb = telebot.TeleBot(TOKEN)
ret_msg = tb.send_audio(CHAT_ID, file_data, 1, performer='eternnoir', title='pyTelegram') ret_msg = tb.send_audio(CHAT_ID, file_data, 1, performer='eternnoir', title='pyTelegram')
assert ret_msg.content_type == 'audio' assert ret_msg.content_type == 'audio'
assert ret_msg.audio.performer == 'eternnoir' assert ret_msg.audio.performer == 'eternnoir'
@ -200,7 +200,7 @@ class TestTeleBot:
def test_send_audio_dis_noti(self): def test_send_audio_dis_noti(self):
file_data = open('./test_data/record.mp3', 'rb') file_data = open('./test_data/record.mp3', 'rb')
tb = pytelegrambotapi.TeleBot(TOKEN) tb = telebot.TeleBot(TOKEN)
ret_msg = tb.send_audio(CHAT_ID, file_data, 1, performer='eternnoir', title='pyTelegram', ret_msg = tb.send_audio(CHAT_ID, file_data, 1, performer='eternnoir', title='pyTelegram',
disable_notification=True) disable_notification=True)
assert ret_msg.content_type == 'audio' assert ret_msg.content_type == 'audio'
@ -209,19 +209,19 @@ class TestTeleBot:
def test_send_voice(self): def test_send_voice(self):
file_data = open('./test_data/record.ogg', 'rb') file_data = open('./test_data/record.ogg', 'rb')
tb = pytelegrambotapi.TeleBot(TOKEN) tb = telebot.TeleBot(TOKEN)
ret_msg = tb.send_voice(CHAT_ID, file_data) ret_msg = tb.send_voice(CHAT_ID, file_data)
assert ret_msg.voice.mime_type == 'audio/ogg' assert ret_msg.voice.mime_type == 'audio/ogg'
def test_send_voice_dis_noti(self): def test_send_voice_dis_noti(self):
file_data = open('./test_data/record.ogg', 'rb') file_data = open('./test_data/record.ogg', 'rb')
tb = pytelegrambotapi.TeleBot(TOKEN) tb = telebot.TeleBot(TOKEN)
ret_msg = tb.send_voice(CHAT_ID, file_data, disable_notification=True) ret_msg = tb.send_voice(CHAT_ID, file_data, disable_notification=True)
assert ret_msg.voice.mime_type == 'audio/ogg' assert ret_msg.voice.mime_type == 'audio/ogg'
def test_get_file(self): def test_get_file(self):
file_data = open('./test_data/record.ogg', 'rb') file_data = open('./test_data/record.ogg', 'rb')
tb = pytelegrambotapi.TeleBot(TOKEN) tb = telebot.TeleBot(TOKEN)
ret_msg = tb.send_voice(CHAT_ID, file_data) ret_msg = tb.send_voice(CHAT_ID, file_data)
file_id = ret_msg.voice.file_id file_id = ret_msg.voice.file_id
file_info = tb.get_file(file_id) file_info = tb.get_file(file_id)
@ -229,7 +229,7 @@ class TestTeleBot:
def test_get_file_dis_noti(self): def test_get_file_dis_noti(self):
file_data = open('./test_data/record.ogg', 'rb') file_data = open('./test_data/record.ogg', 'rb')
tb = pytelegrambotapi.TeleBot(TOKEN) tb = telebot.TeleBot(TOKEN)
ret_msg = tb.send_voice(CHAT_ID, file_data, disable_notification=True) ret_msg = tb.send_voice(CHAT_ID, file_data, disable_notification=True)
file_id = ret_msg.voice.file_id file_id = ret_msg.voice.file_id
file_info = tb.get_file(file_id) file_info = tb.get_file(file_id)
@ -237,19 +237,19 @@ class TestTeleBot:
def test_send_message(self): def test_send_message(self):
text = 'CI Test Message' text = 'CI Test Message'
tb = pytelegrambotapi.TeleBot(TOKEN) tb = telebot.TeleBot(TOKEN)
ret_msg = tb.send_message(CHAT_ID, text) ret_msg = tb.send_message(CHAT_ID, text)
assert ret_msg.message_id assert ret_msg.message_id
def test_send_message_dis_noti(self): def test_send_message_dis_noti(self):
text = 'CI Test Message' text = 'CI Test Message'
tb = pytelegrambotapi.TeleBot(TOKEN) tb = telebot.TeleBot(TOKEN)
ret_msg = tb.send_message(CHAT_ID, text, disable_notification=True) ret_msg = tb.send_message(CHAT_ID, text, disable_notification=True)
assert ret_msg.message_id assert ret_msg.message_id
def test_send_message_with_markup(self): def test_send_message_with_markup(self):
text = 'CI Test Message' text = 'CI Test Message'
tb = pytelegrambotapi.TeleBot(TOKEN) tb = telebot.TeleBot(TOKEN)
markup = types.ReplyKeyboardMarkup() markup = types.ReplyKeyboardMarkup()
markup.add(types.KeyboardButton("1")) markup.add(types.KeyboardButton("1"))
markup.add(types.KeyboardButton("2")) markup.add(types.KeyboardButton("2"))
@ -258,7 +258,7 @@ class TestTeleBot:
def test_send_message_with_markup_use_string(self): def test_send_message_with_markup_use_string(self):
text = 'CI Test Message' text = 'CI Test Message'
tb = pytelegrambotapi.TeleBot(TOKEN) tb = telebot.TeleBot(TOKEN)
markup = types.ReplyKeyboardMarkup() markup = types.ReplyKeyboardMarkup()
markup.add("1") markup.add("1")
markup.add("2") markup.add("2")
@ -269,7 +269,7 @@ class TestTeleBot:
def test_send_message_with_inlinemarkup(self): def test_send_message_with_inlinemarkup(self):
text = 'CI Test Message' text = 'CI Test Message'
tb = pytelegrambotapi.TeleBot(TOKEN) tb = telebot.TeleBot(TOKEN)
markup = types.InlineKeyboardMarkup() markup = types.InlineKeyboardMarkup()
markup.add(types.InlineKeyboardButton("Google", url="http://www.google.com")) markup.add(types.InlineKeyboardButton("Google", url="http://www.google.com"))
markup.add(types.InlineKeyboardButton("Yahoo", url="http://www.yahoo.com")) markup.add(types.InlineKeyboardButton("Yahoo", url="http://www.yahoo.com"))
@ -278,28 +278,28 @@ class TestTeleBot:
def test_forward_message(self): def test_forward_message(self):
text = 'CI forward_message Test Message' text = 'CI forward_message Test Message'
tb = pytelegrambotapi.TeleBot(TOKEN) tb = telebot.TeleBot(TOKEN)
msg = tb.send_message(CHAT_ID, text) msg = tb.send_message(CHAT_ID, text)
ret_msg = tb.forward_message(CHAT_ID, CHAT_ID, msg.message_id) ret_msg = tb.forward_message(CHAT_ID, CHAT_ID, msg.message_id)
assert ret_msg.forward_from assert ret_msg.forward_from
def test_forward_message_dis_noti(self): def test_forward_message_dis_noti(self):
text = 'CI forward_message Test Message' text = 'CI forward_message Test Message'
tb = pytelegrambotapi.TeleBot(TOKEN) tb = telebot.TeleBot(TOKEN)
msg = tb.send_message(CHAT_ID, text) msg = tb.send_message(CHAT_ID, text)
ret_msg = tb.forward_message(CHAT_ID, CHAT_ID, msg.message_id, disable_notification=True) ret_msg = tb.forward_message(CHAT_ID, CHAT_ID, msg.message_id, disable_notification=True)
assert ret_msg.forward_from assert ret_msg.forward_from
def test_reply_to(self): def test_reply_to(self):
text = 'CI reply_to Test Message' text = 'CI reply_to Test Message'
tb = pytelegrambotapi.TeleBot(TOKEN) tb = telebot.TeleBot(TOKEN)
msg = tb.send_message(CHAT_ID, text) msg = tb.send_message(CHAT_ID, text)
ret_msg = tb.reply_to(msg, text + ' REPLY') ret_msg = tb.reply_to(msg, text + ' REPLY')
assert ret_msg.reply_to_message.message_id == msg.message_id assert ret_msg.reply_to_message.message_id == msg.message_id
def test_register_for_reply(self): def test_register_for_reply(self):
text = 'CI reply_to Test Message' text = 'CI reply_to Test Message'
tb = pytelegrambotapi.TeleBot(TOKEN) tb = telebot.TeleBot(TOKEN)
msg = tb.send_message(CHAT_ID, text, reply_markup=types.ForceReply()) msg = tb.send_message(CHAT_ID, text, reply_markup=types.ForceReply())
reply_msg = tb.reply_to(msg, text + ' REPLY') reply_msg = tb.reply_to(msg, text + ' REPLY')
@ -311,7 +311,7 @@ class TestTeleBot:
tb.process_new_messages([reply_msg]) tb.process_new_messages([reply_msg])
def test_send_location(self): def test_send_location(self):
tb = pytelegrambotapi.TeleBot(TOKEN) tb = telebot.TeleBot(TOKEN)
lat = 26.3875591 lat = 26.3875591
lon = -161.2901042 lon = -161.2901042
ret_msg = tb.send_location(CHAT_ID, lat, lon) ret_msg = tb.send_location(CHAT_ID, lat, lon)
@ -319,7 +319,7 @@ class TestTeleBot:
assert int(ret_msg.location.latitude) == int(lat) assert int(ret_msg.location.latitude) == int(lat)
def test_send_location_dis_noti(self): def test_send_location_dis_noti(self):
tb = pytelegrambotapi.TeleBot(TOKEN) tb = telebot.TeleBot(TOKEN)
lat = 26.3875591 lat = 26.3875591
lon = -161.2901042 lon = -161.2901042
ret_msg = tb.send_location(CHAT_ID, lat, lon, disable_notification=True) ret_msg = tb.send_location(CHAT_ID, lat, lon, disable_notification=True)
@ -327,7 +327,7 @@ class TestTeleBot:
assert int(ret_msg.location.latitude) == int(lat) assert int(ret_msg.location.latitude) == int(lat)
def test_send_venue(self): def test_send_venue(self):
tb = pytelegrambotapi.TeleBot(TOKEN) tb = telebot.TeleBot(TOKEN)
lat = 26.3875591 lat = 26.3875591
lon = -161.2901042 lon = -161.2901042
ret_msg = tb.send_venue(CHAT_ID, lat, lon, "Test Venue", "1123 Test Venue address") ret_msg = tb.send_venue(CHAT_ID, lat, lon, "Test Venue", "1123 Test Venue address")
@ -335,50 +335,50 @@ class TestTeleBot:
assert int(lat) == int(ret_msg.venue.location.latitude) assert int(lat) == int(ret_msg.venue.location.latitude)
def test_send_venue_dis_noti(self): def test_send_venue_dis_noti(self):
tb = pytelegrambotapi.TeleBot(TOKEN) tb = telebot.TeleBot(TOKEN)
lat = 26.3875591 lat = 26.3875591
lon = -161.2901042 lon = -161.2901042
ret_msg = tb.send_venue(CHAT_ID, lat, lon, "Test Venue", "1123 Test Venue address", disable_notification=True) ret_msg = tb.send_venue(CHAT_ID, lat, lon, "Test Venue", "1123 Test Venue address", disable_notification=True)
assert ret_msg.venue.title == "Test Venue" assert ret_msg.venue.title == "Test Venue"
def test_Chat(self): def test_Chat(self):
tb = pytelegrambotapi.TeleBot(TOKEN) tb = telebot.TeleBot(TOKEN)
me = tb.get_me() me = tb.get_me()
msg = tb.send_message(CHAT_ID, 'Test') msg = tb.send_message(CHAT_ID, 'Test')
assert me.id == msg.from_user.id assert me.id == msg.from_user.id
assert msg.chat.id == int(CHAT_ID) assert msg.chat.id == int(CHAT_ID)
def test_edit_message_text(self): def test_edit_message_text(self):
tb = pytelegrambotapi.TeleBot(TOKEN) tb = telebot.TeleBot(TOKEN)
msg = tb.send_message(CHAT_ID, 'Test') msg = tb.send_message(CHAT_ID, 'Test')
new_msg = tb.edit_message_text('Edit test', chat_id=CHAT_ID, message_id=msg.message_id) new_msg = tb.edit_message_text('Edit test', chat_id=CHAT_ID, message_id=msg.message_id)
assert new_msg.text == 'Edit test' assert new_msg.text == 'Edit test'
def test_edit_message_caption(self): def test_edit_message_caption(self):
file_data = open('../examples/detailed_example/kitten.jpg', 'rb') file_data = open('../examples/detailed_example/kitten.jpg', 'rb')
tb = pytelegrambotapi.TeleBot(TOKEN) tb = telebot.TeleBot(TOKEN)
msg = tb.send_document(CHAT_ID, file_data, caption="Test") msg = tb.send_document(CHAT_ID, file_data, caption="Test")
new_msg = tb.edit_message_caption(caption='Edit test', chat_id=CHAT_ID, message_id=msg.message_id) new_msg = tb.edit_message_caption(caption='Edit test', chat_id=CHAT_ID, message_id=msg.message_id)
assert new_msg.caption == 'Edit test' assert new_msg.caption == 'Edit test'
def test_get_chat(self): def test_get_chat(self):
tb = pytelegrambotapi.TeleBot(TOKEN) tb = telebot.TeleBot(TOKEN)
ch = tb.get_chat(GROUP_ID) ch = tb.get_chat(GROUP_ID)
assert str(ch.id) == GROUP_ID assert str(ch.id) == GROUP_ID
def test_get_chat_administrators(self): def test_get_chat_administrators(self):
tb = pytelegrambotapi.TeleBot(TOKEN) tb = telebot.TeleBot(TOKEN)
cas = tb.get_chat_administrators(GROUP_ID) cas = tb.get_chat_administrators(GROUP_ID)
assert len(cas) > 0 assert len(cas) > 0
def test_get_chat_members_count(self): def test_get_chat_members_count(self):
tb = pytelegrambotapi.TeleBot(TOKEN) tb = telebot.TeleBot(TOKEN)
cn = tb.get_chat_members_count(GROUP_ID) cn = tb.get_chat_members_count(GROUP_ID)
assert cn > 1 assert cn > 1
def test_edit_markup(self): def test_edit_markup(self):
text = 'CI Test Message' text = 'CI Test Message'
tb = pytelegrambotapi.TeleBot(TOKEN) tb = telebot.TeleBot(TOKEN)
markup = types.InlineKeyboardMarkup() markup = types.InlineKeyboardMarkup()
markup.add(types.InlineKeyboardButton("Google", url="http://www.google.com")) markup.add(types.InlineKeyboardButton("Google", url="http://www.google.com"))
markup.add(types.InlineKeyboardButton("Yahoo", url="http://www.yahoo.com")) markup.add(types.InlineKeyboardButton("Yahoo", url="http://www.yahoo.com"))
@ -407,12 +407,12 @@ class TestTeleBot:
def test_send_video_note(self): def test_send_video_note(self):
file_data = open('./test_data/test_video.mp4', 'rb') file_data = open('./test_data/test_video.mp4', 'rb')
tb = pytelegrambotapi.TeleBot(TOKEN) tb = telebot.TeleBot(TOKEN)
ret_msg = tb.send_video_note(CHAT_ID, file_data) ret_msg = tb.send_video_note(CHAT_ID, file_data)
assert ret_msg.message_id assert ret_msg.message_id
def test_send_media_group(self): def test_send_media_group(self):
tb = pytelegrambotapi.TeleBot(TOKEN) tb = telebot.TeleBot(TOKEN)
img1 = 'https://i.imgur.com/CjXjcnU.png' img1 = 'https://i.imgur.com/CjXjcnU.png'
img2 = 'https://i.imgur.com/CjXjcnU.png' img2 = 'https://i.imgur.com/CjXjcnU.png'
medias = [types.InputMediaPhoto(img1, "View"), types.InputMediaPhoto(img2, "Dog")] medias = [types.InputMediaPhoto(img1, "View"), types.InputMediaPhoto(img2, "Dog")]
@ -424,7 +424,7 @@ class TestTeleBot:
def test_send_media_group_local_files(self): def test_send_media_group_local_files(self):
photo = open('../examples/detailed_example/kitten.jpg', 'rb') photo = open('../examples/detailed_example/kitten.jpg', 'rb')
video = open('./test_data/test_video.mp4', 'rb') video = open('./test_data/test_video.mp4', 'rb')
tb = pytelegrambotapi.TeleBot(TOKEN) tb = telebot.TeleBot(TOKEN)
medias = [types.InputMediaPhoto(photo, "View"), medias = [types.InputMediaPhoto(photo, "View"),
types.InputMediaVideo(video)] types.InputMediaVideo(video)]
result = tb.send_media_group(CHAT_ID, medias) result = tb.send_media_group(CHAT_ID, medias)
@ -434,31 +434,31 @@ class TestTeleBot:
def test_send_photo_formating_caption(self): def test_send_photo_formating_caption(self):
file_data = open('../examples/detailed_example/kitten.jpg', 'rb') file_data = open('../examples/detailed_example/kitten.jpg', 'rb')
tb = pytelegrambotapi.TeleBot(TOKEN) tb = telebot.TeleBot(TOKEN)
ret_msg = tb.send_photo(CHAT_ID, file_data, caption='_italic_', parse_mode='Markdown') ret_msg = tb.send_photo(CHAT_ID, file_data, caption='_italic_', parse_mode='Markdown')
assert ret_msg.caption_entities[0].type == 'italic' assert ret_msg.caption_entities[0].type == 'italic'
def test_send_video_formatting_caption(self): def test_send_video_formatting_caption(self):
file_data = open('./test_data/test_video.mp4', 'rb') file_data = open('./test_data/test_video.mp4', 'rb')
tb = pytelegrambotapi.TeleBot(TOKEN) tb = telebot.TeleBot(TOKEN)
ret_msg = tb.send_video(CHAT_ID, file_data, caption='_italic_', parse_mode='Markdown') ret_msg = tb.send_video(CHAT_ID, file_data, caption='_italic_', parse_mode='Markdown')
assert ret_msg.caption_entities[0].type == 'italic' assert ret_msg.caption_entities[0].type == 'italic'
def test_send_audio_formatting_caption(self): def test_send_audio_formatting_caption(self):
file_data = open('./test_data/record.mp3', 'rb') file_data = open('./test_data/record.mp3', 'rb')
tb = pytelegrambotapi.TeleBot(TOKEN) tb = telebot.TeleBot(TOKEN)
ret_msg = tb.send_audio(CHAT_ID, file_data, caption='<b>bold</b>', parse_mode='HTML') ret_msg = tb.send_audio(CHAT_ID, file_data, caption='<b>bold</b>', parse_mode='HTML')
assert ret_msg.caption_entities[0].type == 'bold' assert ret_msg.caption_entities[0].type == 'bold'
def test_send_voice_formatting_caprion(self): def test_send_voice_formatting_caprion(self):
file_data = open('./test_data/record.ogg', 'rb') file_data = open('./test_data/record.ogg', 'rb')
tb = pytelegrambotapi.TeleBot(TOKEN) tb = telebot.TeleBot(TOKEN)
ret_msg = tb.send_voice(CHAT_ID, file_data, caption='<b>bold</b>', parse_mode='HTML') ret_msg = tb.send_voice(CHAT_ID, file_data, caption='<b>bold</b>', parse_mode='HTML')
assert ret_msg.caption_entities[0].type == 'bold' assert ret_msg.caption_entities[0].type == 'bold'
assert ret_msg.voice.mime_type == 'audio/ogg' assert ret_msg.voice.mime_type == 'audio/ogg'
def test_send_media_group_formatting_caption(self): def test_send_media_group_formatting_caption(self):
tb = pytelegrambotapi.TeleBot(TOKEN) tb = telebot.TeleBot(TOKEN)
img1 = 'https://i.imgur.com/CjXjcnU.png' img1 = 'https://i.imgur.com/CjXjcnU.png'
img2 = 'https://i.imgur.com/CjXjcnU.png' img2 = 'https://i.imgur.com/CjXjcnU.png'
medias = [types.InputMediaPhoto(img1, "*View*", parse_mode='Markdown'), medias = [types.InputMediaPhoto(img1, "*View*", parse_mode='Markdown'),
@ -471,6 +471,6 @@ class TestTeleBot:
def test_send_document_formating_caption(self): def test_send_document_formating_caption(self):
file_data = open('../examples/detailed_example/kitten.jpg', 'rb') file_data = open('../examples/detailed_example/kitten.jpg', 'rb')
tb = pytelegrambotapi.TeleBot(TOKEN) tb = telebot.TeleBot(TOKEN)
ret_msg = tb.send_document(CHAT_ID, file_data, caption='_italic_', parse_mode='Markdown') ret_msg = tb.send_document(CHAT_ID, file_data, caption='_italic_', parse_mode='Markdown')
assert ret_msg.caption_entities[0].type == 'italic' assert ret_msg.caption_entities[0].type == 'italic'

View File

@ -2,7 +2,7 @@
import sys import sys
sys.path.append('../') sys.path.append('../')
from pytelegrambotapi import types from telebot import types
def test_json_user(): def test_json_user():