botman / botman

A framework agnostic PHP library to build chat bots
https://botman.io
MIT License
6.07k stars 811 forks source link

Doesn't get messages from telegram. #738

Closed kurakste closed 6 years ago

kurakste commented 6 years ago

Description:

Hello! Help me please. Now i'm playing around Botman Studio 2.0 in Larvel. I'm using cod from the example. It works great with web interface. I want use it with Telegram. I install drivers, get token. When i try to get registration this way: "php artisan botman:telegram:register" It gets error:

ErrorException : file_get_contents(https://api.telegram.org/bot/setWebhook?url=https://83255e3c.ngrok.io/botman): failed to open stream: HTTP request failed! HTTP/1.1 404 Not Found

The web interface work well with https://83255e3c.ngrok.io/botman/tinker (it the use same webhook, as i think).

I register webhook on telegram this way: curl -d "url=https://83255e3c.ngrok.io/botman" "https://api.telegram.org/bot524662111:AAF3syuVVVVVVVVV35Goh4lR6pxx1yLY/setWebhook"

Telegram told me Ok. Now i send message to bot using telegram. I see in ngrok's logo it comes as well as from webinteface, but bot doesn't reply. And he does work well wen i send message through web.

Help me please and sorry for my english. I will study hard. I promise

christophrumpel commented 6 years ago

Hey @kurakste ,

have you placed your Telegram Token in your env file? From the first error, it seems that the token is missing in the URL.

kurakste commented 6 years ago

No, i don't. I placed it in app/config/botman/telegram.php this way:

`<?php

 return [

     /*
     |--------------------------------------------------------------------------
     | Telegram Token
     |--------------------------------------------------------------------------
     |
     | Your Telegram bot token you received after creating
     | the chatbot through Telegram.
     |
     */
    'token' => env('524662121:AAF3syuak7PcXrvHZuB35Goh4lR6pxx1yLY'),

]; ` Am I wrong? How it has to be paced in .env?

christophrumpel commented 6 years ago

Hey, that's wrong. The string inside the env method is the KEY and not the value. So with your code your are looking for a key called xxx:AAF3syuak7PcXrvHZuB35Goh4lR6xxxpxx1yLY.

Best way is to use it like that env('TELEGRAM_TOKEN') and in your .env file you write TELEGRAM_TOKEN= your_token.

kurakste commented 6 years ago

It's work well. Thank you a lot. The documentations told me:

https://botman.io/2.0/driver-telegram Once you have obtained the access token, place it in your BotMan configuration. If you use BotMan Studio, you can find the configuration file located under config/botman/telegram.php.

I'm a newbie in laravel. It wasn't obvious for me, how it has to be done. Thank you a lot. And product is amazing.

christophrumpel commented 6 years ago

You are right. I will update the docs to make that more clear. Thanks for mentioning 👍

christophrumpel commented 6 years ago

Changes are already in a PR: https://github.com/botman/docs/pull/73

AvneetSingh27 commented 3 years ago

Hey, I am getting the same error file_get_contents(https://api.telegram.org/bot/setWebhook?url=https://1bc20d0d08ce.ngrok.io/botman/tinker): failed to open stream: HTTP request failed! HTTP/1.1 404 Not Found

But this works well:https://1bc20d0d08ce.ngrok.io/botman/tinker at F:\Botman Chatbot\todobot\vendor\botman\driver-telegram\src\Console\Commands\TelegramRegisterCommand.php:44 40| $this->info('Using '.$url); 41| 42| $this->info('Pinging Telegram...'); 43|

44| $output = json_decode(file_get_contents($url)); 45| 46| if ($output->ok == true && $output->result == true) { 47| $this->info( 48| $remove

Exception trace:

1 file_get_contents() F:\Botman Chatbot\todobot\vendor\botman\driver-telegram\src\Console\Commands\TelegramRegisterCommand.php:44

2 BotMan\Drivers\Telegram\Console\Commands\TelegramRegisterCommand::handle() F:\Botman Chatbot\todobot\vendor\laravel\framework\src\Illuminate\Container\BoundMethod.php:29

Though I have set up the telegram auth token in the right manner. But it's sending 404. Please help me in this context