skip to Main Content

I am using telegram.php to connect my bot. When I use sendmessage all of thing is ok in my logs but I do not receive anything from the bot.

When I check my log there is a problem like this:

ok:         False
curl_error_code:        51
curl_error:     SSL: no alternative certificate subject name matches target host name 'api.telegram.org'

I donit know what to do to fix it.

2

Answers


  1. I don’t know this telegram bot, but I see that it uses GuzzleHttp.
    During the initialization it doesn’t accept any configuration Request::initialize()

    public static function initialize(Telegram $telegram)
    {
        if (!($telegram instanceof Telegram)) {
            throw new TelegramException('Invalid Telegram pointer!');
        }
        self::$telegram = $telegram;
        self::setClient(new Client(['base_uri' => self::$api_base_uri]));
    }
    

    you should check its documentation. I see that there are a lot of setters which makes you able to overwrite the default settings.

    What you need is to set the the GuzzleHttpRequestOptions::VERIFY to false in the client config:

    $this->client = new GuzzleHttpClient([
        'base_uri'                          => 'someAccessPoint',
        GuzzleHttpRequestOptions::HEADERS => [
            'User-Agent' => 'some-special-agent',
        ],
        'defaults'                          => [
            GuzzleHttpRequestOptions::CONNECT_TIMEOUT => 5,
            GuzzleHttpRequestOptions::ALLOW_REDIRECTS => true,
        ],
        GuzzleHttpRequestOptions::VERIFY  => false,
    ]);
    
    Login or Signup to reply.
  2. For fix this problem copy this Url to browser and set webhook:

    https://api.telegram.org/botTOKEN/setWebhook?url=https://yourwebsite.com
    

    Solution 2 of The Error
    Let’s follow these simple steps:

    Download this bundle of root certificates: https://curl.haxx.se/ca/cacert.pem
    Put in any location of your server.
    Open php.ini and add this line:

    curl.cainfo = "[the_location]cacert.pem"
    

    Restart your webserver.
    That’s it. 🙂

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search