سهیل
3 سال پیش توسط سهیل مطرح شد
0 پاسخ

ساخت ربات تلگرام و تنظیم وب هوک

سلام دوستان من ربات تلگرام ساختم میخوام وقتی کاربر داخل ربات start کرد یه پیامی براش فرستاده بشه از ngrok دارم استفاده میکنم
https://api.telegram.org/bot{token}/setWebhook?url=https://fa88-235-226-31.eu.ngrok.io/api/telegram
ولی هر کاری میکنم داخل ngrok ارور 404 not found بهم میده
api/telegram مسیری هستش که داخل پروژه تعریف کردم

Route::post('/telegram' , function()  
{  
new TelegramBotService();  
});

و این هم کلاسی که قراره پیام رو بفرسته

class TelegramBotService  
{
public $data;
public $message;

public function __construct()
{   
    $data = file_get_contents( 'php://input' , true );
    $data = json_decode( $data , true);
    $this->get_telegramMessage($data);
}

public function get_telegramMessage($data)
{
    $message = $data[ 'message' ];
    $this->get_telegramChatID($data , $message);
}

public function get_telegramChatID($data , $message)
{
    $chat_id = $data[ 'message' ][ 'chat' ][ 'id' ];dd($chat_id);
    $this->sendChatIdToUser($chat_id , $message);
}

public function sendChatIdToUser($chat_id , $message)
{
    if ( $message === '/start' )
    {
           Telegram::sendMessage([
                'chat_id' => $chat_id,
                'text' => ''
            ]);
    }else{
        Telegram::sendMessage([
            'text' => 'lotfan start ra vared konid'
        ]);
    }
}

}
ممنون میشم کمکم کنید