def webhook(): bot.remove_webhook() bot.set_webhook(url='https://lizatish-telegram-bot.herokuapp.com/' + app.config['TELEGRAM_TOKEN']) # bot.set_webhook(url='https://7308fa93b393.ngrok.io/' + app.config['TELEGRAM_TOKEN']) return "!", 200
def webhook(): try: bot.remove_webhook() time.sleep(0.4) bot.set_webhook(Config.URL + Config.secret) print("webhook set") except Exception as e: bot.send_message(message.chat.id, text="Ошибка " + str(e)) return "Ошибка ", e return "!", 200
def set_webhook(): bot.remove_webhook() if DEBUG: res = bot.set_webhook(f'{NGROK_DEPLOY_DOMAIN}/{TOKEN}') else: res = bot.set_webhook(f'{HEROKU_DEPLOY_DOMAIN}/{TOKEN}') if res: return "webhook setup ok" else: return "webhook setup failed"
def admin_settings(): if current_user.role == 'admin' or current_user.role == 'moderator': webhook_form = ChangeWebhookForm() if webhook_form.validate_on_submit(): try: bot.set_webhook(url=webhook_form.url.data) flash(f'Вебхук установлен на {webhook_form.url.data}') except(TelegramError): flash(f'Вебхук не установлен. Ошибка {str(TelegramError)}') webhook_form.url.data = url_for('telegram_bot.telegram', _external=True) return render_template('admin/admin_settings.html', title='Настройки', form=webhook_form) else: return redirect(url_for('main.index'))
def web_hook(): bot.remove_webhook() bot.set_webhook(url=config.URL + config.TOKEN) return "!", 200
def webhook(): """Установка webhook'a """ bot.remove_webhook() bot.set_webhook(url=current_app.config["WEB_HOOK_URL"] + "setwebhook") return "!", 200
from app import app, db, bot, config from DB.models import * from webserver import * from bot_events import * def create_tables(): # Chat.create_table() # User.create_table() # CalendarEvent.create_table() ChatsUsers = Chat.users.get_through_model() db.database.create_tables( [Chat, User, CalendarEvent, Calendar, ChatsUsers], safe=True) if __name__ == '__main__': bot.remove_webhook() bot.set_webhook(url=config.WEBHOOK_URL_BASE + config.WEBHOOK_URL_PATH) create_tables() app.run(host=config.WEBHOOK_LISTEN, port=config.WEBHOOK_LOCAL_PORT, debug=False)
def webhook(): bot.remove_webhook() bot.set_webhook(url='https://python-review-test-bot.herokuapp.com/' + BOT_TOKEN) return "!", 200
def set_hook(): APP_NAME = os.getenv('HEROKU_APP_NAME') DOMAIN = os.getenv('HEROKU_DOMAIN') WEB_HOOK_URL = f'https://{APP_NAME}.{DOMAIN}/telegram' print('WEB_HOOK_URL', WEB_HOOK_URL) print(bot.set_webhook(url=WEB_HOOK_URL))
import time from app import bot, WEBHOOK_HOST, WEBHOOK_PATH webhook_url = WEBHOOK_HOST + WEBHOOK_PATH print(bot.remove_webhook()) time.sleep(3) print('Webhook set to', webhook_url) print(bot.set_webhook(url=webhook_url))
if (expert.ActiveUserId > 0): bot.send_message(expert.UserChatId, message.text) else: bot.reply_to(message, "First wait a question!") # if message from user than send message to expert else: experts1 = models.Users.query.filter_by(ActiveUserId=message.from_user.id) if (experts1.count() > 0): expert1 = experts1.first() bot.send_message(expert1.ExpertChatId, message.text) else: bot.reply_to(message, "First find the expert!") """ #bot.polling() # Remove webhook, it fails sometimes the set if there is a previous webhook bot.remove_webhook() bot.set_webhook(url=WEBHOOK_URL_BASE+WEBHOOK_URL_PATH, certificate=open(WEBHOOK_SSL_CERT, 'r')) #print WEBHOOK_SSL_CERT #print WEBHOOK_SSL_PRIV # Start flask server if __name__ == "__main__": app.run() # app.run(host=WEBHOOK_LISTEN, # port=WEBHOOK_PORT, # ssl_context=(WEBHOOK_SSL_CERT, WEBHOOK_SSL_PRIV), # debug=True)