from threading import Timer
class RepeatTimer(Timer):
def run(self):
while not self.finished.wait(self.interval):
self.function(*self.args, **self.kwargs)
def notify():
bot.send_message(id, 'живой я, живой') # id = telegram id (int)
if __name__ == '__main__':
RepeatTimer(300, notify).start() # время в секундах, название функции (! не сама функция)
@bot.message_handler(commands=['начать'])
def getchatid(message):
bot.send_message(message.chat.id, 'ID: {}'.format(message.chat.id))
Set proxy host:port in zbxtg_settings.py if you need an internet proxy (socks5 supported as well, the wiki will help you)
@bot.message_handler(commands=['subscribe'])
def send_welcome(message):
global sub
sub = [line.rstrip('\n') for line in open(subscribefile, 'rt')]
if str(message.text) not in sub:
with open(subscribefile, 'a') as f:
f.write(str(message.text) + "\n")
sub = [line.rstrip('\n') for line in open(subscribefile, 'rt')]
bot.send_message(message.chat.id, "Подписка оформлена. Для отмены подписки /unsubscribe")
else:
bot.send_message(message.chat.id, "У Вас уже есть активная подписка. Для отмены подписки /unsubscribe")
#! /usr/bin/python3
# -*- coding: UTF-8 -*-
import requests
import json
proxy = {'https': 'socks5h://user:password@IP:1080'}
token = '123:ABC'
chat_id = 123
URL = 'https://api.telegram.org/bot' + token + '/sendMessage'
reply_markup ={ "keyboard": [["Yes", "No"], ["Maybe"], ["1", "2", "3"]], "resize_keyboard": True}
data = {'chat_id': chat_id, 'text': '123', 'reply_markup': json.dumps(reply_markup)}
r = requests.post(URL, data=data, proxies=proxy)
print(r.json())
@bot.message_handler(commands=['start'])
def hadle_text(message):
user_markup = telebot.types.ReplyKeyboardMarkup(True, True)
button_phone = types.KeyboardButton(text="Отправить номер телефона", request_contact=True)
user_markup.add(button_phone)
send = bot.send_message(message.chat.id, 'Поделитесь своим номером, чтобы я нашёл Ваши заказы',
reply_markup=user_markup)