Problems with Return Botman + Httpful

Asked

Viewed 29 times

2

My project consists of a chatbot that receives user information, consults an api created by me with this information, and must present to the user the return of this query. This return is a list of JSON’s. To create the bot, I’m using the framework Botman, and to make the requisitions, the library httpful. My problem is time to present the return to the user, which Botman cannot present.

Function:

public function pega_dados(){
    if($this->tipo == 'Produto'){ $aux = 1; }
    else { $aux = 2; }
    $uri = "localhost:7000/weight/?i=$aux&a=$this->descricao";
    $response = \Httpful\Request::get($uri)->send();

    $this->say($response->body[0]->id);

}

This return that is not being presented: $this->say($response->body[0]->id);.

If I just let: $this->say($response->body);and make a request that generates error in my API, it correctly returns the error. Otherwise, nothing happens and I have no return.

1 answer

2


Instead of trying to make the bot return 'Say' within this function, try the following:

public function pega_dados(){
if($this->tipo == 'Produto'){ $aux = 1; }
else { $aux = 2; }
$uri = "localhost:7000/weight/?i=$aux&a=$this->descricao";
$response = \Httpful\Request::get($uri)->send();

return $response->body[0]->id;

}

And where you call the function pega_dados(), put your return in a variable and print the variable.

$aux= $this->pega_dados();
$this->say("$aux");
  • Man, thank you so much! Solved my problem!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.