B
B
Boy2018-07-30 01:04:05
Java
Boy, 2018-07-30 01:04:05

Telegram Bot Java - how to make the bot work via Webhook?

Good day. I am creating a telegram bot in java using the rubengulas api. And I can't set up a webhook in any way.
I know that there are following rules for webhook, specified in the official telegram documentation:

*Supports IPv4, IPv6 is currently not supported for Webhooks.

*Accepts incoming POSTs from 149.154.167.197-233 on port 443,80,88 or 8443.

*Is able to handle TLS1.0+ HTTPS-traffic.

*Provides a supported, non-wildcard, verified or self-signed certificate.

*Uses a CN or SAN that matches the domain you’ve supplied on setup.

*Supplies all intermediate certificates to complete a verification chain.

I have a domain with a verified certificate. The server listens on port 443 and accepts post requests from addresses 149.154.167.197-233.
I use here this rubengulas api method to create Telegram api
private static TelegramBotsApi createNoSelfSignedTelegramBotsApi() throws TelegramApiException {
        return new TelegramBotsApi(
               "src/main/resources/server.jks",//path to KeyStore for the server 
               "myPassword",                   //Key store password for the serve
               "https://example.com:443",      //External url
               "https://localhost:443");       //Internal url
    }

I got the .jks file using the following commands from the pem files of a valid certificate on the server:
openssl pkcs12 -export -in mydomain.net.crt -inkey mydomain.key > keypair.p12
keytool -importkeystore -srckeystore keypair.p12 -destkeystore server.jks -srcstoretype pkcs12

I started the bot like this:
ApiContextInitializer.init();
    TelegramBotsApi botsApi = new TelegramBotsApi(
                           "src/main/resources/server.jks",
                           "mypassword",
                           "https://example.com:443",
                           "https://localhost:443");
   BotHook webhookBot = new BotHook(options);
   botsApi.registerBot(webhookBot)

The Telegram api creates a grizzly http server, which writes the following when the bot starts:
Jul 28, 2018 3:27:59 PM org.glassfish.grizzly.http.server.NetworkListener start

INFO: Started listener bound to [localhost:443]

Jul 28, 2018 3:27:59 PM org.glassfish.grizzly.http.server.HttpServer start

INFO: [HttpServer] Started.

There are no more errors when starting the program. But in the server logs I saw the following error
2018/07/29 15:08:43 [error] 1166#1166: *453 openat() "/var/www/www-root/data/www/mydomain.net/callback/WebhookClass failed (2: No such file or directory),
 client: 149.154.167.227, server: mydomain.net request: 
"POST /callback/WebhookClass HTTP/1.1", host: "mydomain.net"

It looks like my post request can't be processed due to the wrong url to the webhook. But I don't understand what url should be specified, because the bot is going to a jar archive,
and the webhook processing class is in it. Please tell me.

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question