Exemple #1
0
from application.bot import registration, catalog, notifications

if 'PRODUCTION' in os.environ:
    @bp.route(Config.WEBHOOK_URL_PATH, methods=['POST'])
    def receive_message():
        if request.headers.get('content-type') == 'application/json':
            json_string = request.get_data().decode('utf-8')
            update = telebot.types.Update.de_json(json_string)
            telegram_bot.process_new_updates([update])
            return ''
        else:
            abort(400)


    telegram_bot.remove_webhook()
    telegram_bot.set_webhook(Config.WEBHOOK_URL_BASE + Config.WEBHOOK_URL_PATH)


@telegram_bot.message_handler(commands=['sorrytest'])
def send_test_sorry_message(message: telebot.types.Message):
    message_text = 'Коллектив “Домашней кухни” приносит свои извинения за предоставленные неудобства в виде ' \
                   'задержек доставки. Это первые дни работы с нашей собственной доставкой через БОТ, ' \
                   'честно говоря, мы не ожидали такого потока клиентов и наш сервис не был к этому подготовлен. ' \
                   'Просим Вас, понять нашу ситуацию. С нашей стороны мы каждому обещаем при следующей доставке комплимент ' \
                   'от заведения совершенно бесплатно(Важно! Не забудьте напомнить при заказе об этом!). ' \
                   'Пишите обязательно нам свои отзывы и замечания, нам важно каждое мнение!'
    test_ids = [76777495, 294957271]
    for id in test_ids:
        try:
            telegram_bot.send_message(id, message_text)
Exemple #2
0
from flask import Blueprint, request, abort
from application import telegram_bot as bot, logger
from config import Config
from telebot.types import Update
import os
import logging

bp = Blueprint('bot', __name__)

# Load bot's behaviors
from application.bot import core

if 'PRODUCTION' in os.environ:
    # When app started in production, configure Telegram webhook to receive updates
    @bp.route(Config.WEBHOOK_URL_PATH, methods=['POST'])
    def receive_message():
        if request.headers.get('content-type') == 'application/json':
            json_string = request.get_data().decode('utf-8')
            update = Update.de_json(json_string)
            bot.process_new_updates([update])
            return ''
        else:
            abort(400)

    bot.remove_webhook()
    bot.set_webhook(Config.WEBHOOK_URL_BASE + '/bot' + Config.WEBHOOK_URL_PATH,
                    certificate=open(Config.WEBHOOK_SSL_CERT, 'r'))