def handle(self, *args, **options):
        # setWebhook for the bot
        if settings.TELEGRAM_TOKEN:
            webhook_uri = reverse("webhook_telegram", kwargs={"token": settings.TELEGRAM_TOKEN})
            bot.set_webhook("https://vas3k.club" + webhook_uri)

        self.stdout.write("Done 🥙")
Beispiel #2
0
    def do_GET(self):
        bot.remove_webhook()
        sleep(5)
        bot.set_webhook(url='https://xo-telegram-bot.herokuapp.com/' +
                        bot.token)

        self.send_response(200)
        self.end_headers()
        self.wfile.write(b'Webhook set')
Beispiel #3
0
def set_webhook(request):
    try:
        url = reverse('webhook-handle')
        url = request.build_absolute_uri(url)
        bot.remove_webhook()
        bot.set_webhook(url)
        logger.info(f'Webhook was set to:{url}')
        return Response('Webhook was successfully set.')
    except Exception as e:
        logger.exception('Error while setting webhook.')
        return Response(str(e))
Beispiel #4
0
def webhook(request, token):
    if request.method == 'GET':
        try:
            bot.remove_webhook()
            bot.set_webhook(f"{os.getenv('APP_URL')}/{token}")
            return Response('Webhook was successfully set.')
        except Exception as e:
            return Response(str(e))

    elif request.method == 'POST':
        bot.process_new_updates([telebot.types.Update.de_json(request.data)])
        return Response('!')
Beispiel #5
0
from bot.bot import bot
from bot.bot import *

WEBHOOK_SSL_CERT = os.path.join(BASE_DIR, 'webhook_cert.pem')


class ProcessWebhook(View):
    def post(self, request):
        if 'content-length' in request.headers and \
                        'content-type' in request.headers and \
                        request.headers['content-type'] == 'application/json':
            json_string = request.body.decode("UTF-8")
            update = telebot.types.Update.de_json(json_string)
            bot.process_new_updates([update])
            return HttpResponse('')
        else:
            return HttpResponse(status=403)

    def get(self, request):
        return HttpResponse('Hello')


if "runserver" in sys.argv:
    bot.remove_webhook()
    import threading
    threading.Thread(target=bot.polling, kwargs={"none_stop": True}).start()
else:
    bot.remove_webhook()
    bot.set_webhook(url=f'https://{DOMAIN}/webhook/',
                    certificate=open(WEBHOOK_SSL_CERT, 'r'))