B
B
Bruceee2017-08-06 14:18:16
Bots
Bruceee, 2017-08-06 14:18:16

Webhook on https but without the certificate .pem file itself?

Good afternoon!

I'm trying to set up a telegram bot to work through a webhook, but it doesn't work. I am using pyTelegramBotAPI.
Through the interface of my host, I made SSL certificates for the domain, the rating https://www.ssllabs.com/ssltest/ gives A.

I don’t fully understand how exactly I need to register a webhook via setwebhook in telegram. Everything seems to have gone well. Here is my setwebhook function:

WEBHOOK_URL_BASE = "https://%s:%s" % (WEBHOOK_HOST, WEBHOOK_PORT)
WEBHOOK_URL_PATH = "/%s/" % (API_TOKEN)

@app.route('/set_webhook', methods=['GET', 'POST']) 
def set_webhook(): 
    s = bot.set_webhook(url=WEBHOOK_URL_BASE+WEBHOOK_URL_PATH)
    if s:
        print(s)
        return "webhook setup ok" 
    else: 
        return "webhook setup failed"

It returns webhook setup ok.

This is the telegram webhook request handler:
# Process webhook calls
@app.route(WEBHOOK_URL_PATH, methods=['POST'])
def webhook():
    if flask.request.headers.get('content-type') == 'application/json':
        json_string = flask.request.get_data().decode('utf-8')
        update = telebot.types.Update.de_json(json_string)
        bot.process_new_updates([update])
        return ''
    else:
        flask.abort(403)


My hosting provider (beget.ru) does not issue SSL certificates registered through their interface, and in order to install their own certificates, you need a dedicated IP address for an additional fee. Telegram says: "2. To use a self-signed certificate, you need to upload your public key certificate using certificate parameter." My certificate does not seem to be self-signed, because the certificate was registered by the hoster (this point is not clear to me until the end).
Therefore, I wanted to clarify, if the site is already on https, and the telegram's certificate parameter in the setWebhook method is optional, then how can I configure the webhook correctly in my case?

The full code for my __init__.py file is here: https://pastebin.com/0SUrTKN1

Based on thispyTelegramBotAPI library example.

If you ate a dog on telegram bots, please tell me how to make a webhook without having the .pem certificate itself? Do I need to write something to BotFather to register a webhook? How can you check that telegram is at least trying to make a POST request to the specified address? How can I check the intermediate steps for configuring a webhook for a bot?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
P
Pavel Volintsev, 2017-08-06
@copist

You configure a webhook on HTTPS and you cannot attach SSL. So it can't work.
1. Try to make your bot work over HTTP if it's allowed
2. Change hoster, get VDS, install your own SSL (I can recommend DigitalOcean or FirstVDS

C
CityCat4, 2017-08-07
@CityCat4

made SSL certificates for the domain

That is, the hoster did something shamanistic and there is SSL, but the certificate itself does not issue? :) Without a certificate file, nothing will work. Most likely to change the hoster - what the hell is so smart.

A
Andrey Shatokhin, 2017-08-07
@Sovigod

Your daemon is listening on port 8443.
WEBHOOK_PORT = 8443
And there is no certificate there. There's a simple http. Generate a certificate and add it to app.run and bot.set_webhook

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question