Skip to content

Commit 9c3886f

Browse files
committed
First Init.
0 parents  commit 9c3886f

File tree

4 files changed

+237
-0
lines changed

4 files changed

+237
-0
lines changed

.gitignore

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
# Byte-compiled / optimized / DLL files
2+
__pycache__/
3+
*.py[cod]
4+
5+
# C extensions
6+
*.so
7+
8+
# Distribution / packaging
9+
.Python
10+
env/
11+
build/
12+
develop-eggs/
13+
dist/
14+
downloads/
15+
eggs/
16+
.eggs/
17+
lib/
18+
lib64/
19+
parts/
20+
sdist/
21+
var/
22+
*.egg-info/
23+
.installed.cfg
24+
*.egg
25+
26+
.idea/
27+
venv/
28+
29+
# PyInstaller
30+
# Usually these files are written by a python script from a template
31+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
32+
*.manifest
33+
*.spec
34+
35+
# Installer logs
36+
pip-log.txt
37+
pip-delete-this-directory.txt
38+
39+
# Unit test / coverage reports
40+
htmlcov/
41+
.tox/
42+
.coverage
43+
.coverage.*
44+
.cache
45+
nosetests.xml
46+
coverage.xml
47+
*,cover
48+
49+
# Translations
50+
*.mo
51+
*.pot
52+
53+
# Django stuff:
54+
*.log
55+
56+
# Sphinx documentation
57+
docs/_build/
58+
59+
# PyBuilder
60+
target/
61+
testMain.py

telebot/__init__.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# -*- coding: utf-8 -*-
2+
3+
import apihelper
4+
5+
"""
6+
Module : telebot
7+
"""
8+
9+
API_URL = r"https://api.telegram.org/"
10+
11+
12+
class TeleBot:
13+
""" This is TeleBot Class
14+
Methods:
15+
getMe
16+
sendMessage
17+
forwardMessage
18+
sendPhoto
19+
sendAudio
20+
sendDocument
21+
sendSticker
22+
sendVideo
23+
sendLocation
24+
sendChatAction
25+
getUserProfilePhotos
26+
getUpdates
27+
setWebhook
28+
"""
29+
30+
def __init__(self, token):
31+
self.token = token
32+
33+
def get_me(self):
34+
# TODO
35+
return None
36+
37+
def send_message(self, chat_id, text, disable_web_page_preview=None, reply_to_message_id=None, reply_markup=None):
38+
return apihelper.send_message(self.token, chat_id, text, disable_web_page_preview, reply_to_message_id,
39+
reply_markup)

telebot/apihelper.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# -*- coding: utf-8 -*-
2+
3+
import telebot
4+
import requests
5+
6+
7+
def send_message(token, chat_id, text, disable_web_page_preview=None, reply_to_message_id=None, reply_markup=None):
8+
api_url = telebot.API_URL
9+
method_url = r'sendMessage'
10+
request_url = api_url + 'bot' + token + '/' + method_url
11+
paras = 'chat_id=' + str(chat_id) + '&text=' + text
12+
if disable_web_page_preview:
13+
paras = paras + '&disable_web_page_preview=' + disable_web_page_preview
14+
if reply_to_message_id:
15+
paras = paras + '&reply_to_message_id=' + reply_to_message_id
16+
if reply_markup:
17+
paras = paras + '&reply_markup=' + reply_markup
18+
request_url = request_url + '?' + paras
19+
req = requests.get(request_url)
20+
return req.json()

telebot/types.py

Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
# -*- coding: utf-8 -*-
2+
"""
3+
Available types
4+
5+
User
6+
GroupChat
7+
Message
8+
PhotoSize
9+
Audio
10+
Document
11+
Sticker
12+
Video
13+
Contact
14+
Location
15+
Update
16+
InputFile
17+
UserProfilePhotos
18+
ReplyKeyboardMarkup
19+
ReplyKeyboardHide
20+
ForceReply
21+
"""
22+
23+
class User:
24+
def __init__(self, id, first_name, last_name=None, username=None):
25+
self.id = id
26+
self.first_name = first_name
27+
self.username = username
28+
self.last_name = last_name
29+
30+
31+
class GroupChat:
32+
def __init__(self, id, title):
33+
self.id = id
34+
self.title = title
35+
36+
37+
class Message:
38+
def __init__(self, message_id, fromUser, date, chat, **options):
39+
# TODO Add options.
40+
self.chat = chat
41+
self.date = date
42+
self.fromUser = fromUser
43+
self.message_id = message_id
44+
45+
46+
class PhotoSize:
47+
def __init__(self, file_id, width, height, file_size):
48+
self.file_size = file_size
49+
self.height = height
50+
self.width = width
51+
self.file_id = file_id
52+
53+
54+
class Audio:
55+
def __init__(self, file_id, duration, mime_type=None, file_size=None):
56+
self.file_id = file_id
57+
self.duration = duration
58+
self.mime_type = mime_type
59+
self.file_size = file_size
60+
61+
62+
class Document:
63+
def __init__(self, file_id, thumb, file_name=None, mime_type=None, file_size=None):
64+
self.file_id = file_id
65+
self.thumb = thumb
66+
self.file_name = file_name
67+
self.mime_type = mime_type
68+
self.file_size = file_size
69+
70+
71+
class Sticker:
72+
def __init__(self, file_id, width, height, thumb, file_size=None):
73+
self.file_id = file_id
74+
self.width = width
75+
self.height = height
76+
self.thumb = thumb
77+
self.file_size = file_size
78+
79+
80+
class Video:
81+
def __init__(self, file_id, width, height, duration, thumb, mime_type=None, file_size=None, caption=None):
82+
self.file_id = file_id
83+
self.width = width
84+
self.height = height
85+
self.duration = duration
86+
self.thumb = thumb
87+
self.mime_type = mime_type
88+
self.file_size = file_size
89+
self.caption = caption
90+
91+
92+
class Contact:
93+
def __init__(self, phone_number, first_name, last_name=None, user_id=None):
94+
self.phone_number = phone_number
95+
self.first_name = first_name
96+
self.last_name = last_name
97+
self.user_id = user_id
98+
99+
100+
class Location:
101+
def __init__(self, longitude,latitude):
102+
self.longitude = longitude
103+
self.latitude = latitude
104+
105+
106+
class UserProfilePhotos:
107+
def __init__(self,total_count,photos):
108+
self.total_count = total_count
109+
self.photos = photos
110+
111+
112+
class ReplyKeyboardMarkup:
113+
def __init__(self,keyboard,resize_keyboard=None,one_time_keyboard=None,selective=None):
114+
self.keyboard = keyboard
115+
self.resize_keyboard = resize_keyboard
116+
self.one_time_keyboard = one_time_keyboard
117+
self.selective = selective

0 commit comments

Comments
 (0)