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

43 lines
1.3 KiB
Python
Raw Normal View History

2015-06-26 09:55:13 +03:00
# -*- coding: utf-8 -*-
import telebot
import requests
2015-06-26 10:46:02 +03:00
def get_me(token):
2015-06-26 13:02:30 +03:00
api_url=telebot.API_URL
2015-06-26 10:46:02 +03:00
method_url = r'getMe'
2015-06-26 13:02:30 +03:00
request_url = api_url+'bot'+token+'/'+method_url
2015-06-26 10:46:02 +03:00
req = requests.get(request_url)
return req.json()
2015-06-26 09:55:13 +03:00
def send_message(token, chat_id, text, disable_web_page_preview=None, reply_to_message_id=None, reply_markup=None):
2015-06-26 10:46:02 +03:00
"""
Use this method to send text messages. On success, the sent Message is returned.
:param token:
:param chat_id:
:param text:
:param disable_web_page_preview:
:param reply_to_message_id:
:param reply_markup:
:return:
"""
2015-06-26 09:55:13 +03:00
api_url = telebot.API_URL
method_url = r'sendMessage'
request_url = api_url + 'bot' + token + '/' + method_url
2015-06-26 10:19:05 +03:00
payload = {'chat_id': str(chat_id), 'text': text}
2015-06-26 09:55:13 +03:00
if disable_web_page_preview:
2015-06-26 10:19:05 +03:00
payload['disable_web_page_preview'] = disable_web_page_preview
2015-06-26 09:55:13 +03:00
if reply_to_message_id:
2015-06-26 10:19:05 +03:00
payload['reply_to_message_id'] = reply_to_message_id
2015-06-26 09:55:13 +03:00
if reply_markup:
2015-06-26 10:19:05 +03:00
payload['reply_markup'] = reply_markup
req = requests.get(request_url, params=payload)
2015-06-26 09:55:13 +03:00
return req.json()
2015-06-26 13:02:30 +03:00
def get_updates(token):
api_url = telebot.API_URL
method_url = r'getUpdates'
request_url = api_url+'bot'+token+'/'+method_url
req = requests.get(request_url)
return req.json()