'WhatsApp chatbot with Twilio using Php

I am trying to create a chatbot using laravel php and Twilio Api. I am still in sandbox. This the code i currently have

public function commandHandler(Request $request){
    $from = $request->input('From'); // phone number where the message is coming from
    $body = $request->input('Body');// what user wrote


    $client = new \GuzzleHttp\Client();
    try {
        $response = $client->request('GET', "https://api.github.com/users/$body"); //test if network is working

        if ($response->getStatusCode() == 200) {
            $message = "Welcome to System. \n";
            $message .= "To Log In, Enter Email Address";

            $this->sendWhatsAppMessage($message, $from);
        } else {
            $this->sendWhatsAppMessage("Error", $from);
        }
    } catch (RequestException $th) {
        $response = json_decode($th->getResponse()->getBody());
        $this->sendWhatsAppMessage($response->message, $from);
    }
    return;


}

I can get what user has typed from the variable $body and send user back a message through the function

$this->sendWhatsAppMessage($response->message, $from);

but the problem is when i want the user to enter password, it goes to the same url and does the same functions of which i would like for it to do different functions. Twilio only accepts one call-back url which i have to use that one function only. How do i use different functions for different messages sent to the user

this is what is in my api.php

Route::post('/chat', 'App\Http\Controllers\ChatBotController@listenToReplies');

and that is the url in the callback of the Twilio dashboard



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source