botman / docs

BotMan documentation
33 stars 52 forks source link

Dialogflow Integration #91

Closed ghost closed 5 years ago

ghost commented 5 years ago

Can anyone provide a detailed example of the Dialogflow implementation?I have created a bot, using the facebook driver and I want to implement Dialogflow to make the interaction more human. The official BotMan documentations are lack about information on the integration of NLP platforms, the example doesn't help much. Thank you

christophrumpel commented 5 years ago

The docs explain the main steps, but it is true that there could be more details. We appreciate every help (PR) to improve the BotMan, all its drivers and the docs ;-)

My first (and crappy) live stream was about that topic, so maybe that helps. Additionally, there is a paid video course by Marcel and one by myself where DialogFlow is explained with BotMan.

ghost commented 5 years ago

The docs explain the main steps, but it is true that there could be more details. We appreciate every help (PR) to improve the BotMan, all its drivers and the docs ;-)

My first (and crappy) live stream was about that topic, so maybe that helps. Additionally, there is a paid video course by Marcel and one by myself where DialogFlow is explained with BotMan.

Ok, I will take a look but more official documentations will be appreciated. For now I'm using the basic example to learn how to integrate Dialogflow, What I need to put in place of my_api_action? This is one part of the basic example that for me isn't much clear.

christophrumpel commented 5 years ago

In Dialogflow you can add an action name to an intent. This action name is what you can listen for in BotMan. It works like this when Dialogflow is connected:

ghost commented 5 years ago

In Dialogflow you can add an action name to an intent. This action name is what you can listen for in BotMan. It works like this when Dialogflow is connected:

  • request from messenger gets to BotMan
  • botman sends the text to DialogFlow
  • DialogFlow checks given intents
  • If one is matched and has an action name, that action name is returned with other information about the intent
  • in BotMan you can now listen for this action like seen in the example

Ok, so if I configure an intent in dialogflow that is something like 'hello botman', I need to pass this to the hears method and then on user input, I need to reply using the botman reply method by passing a reply from dialogflow or a custom one right?

christophrumpel commented 5 years ago

an intent is like an overall topic like the user is greeting us, or the user asks about contact possibilities or the user wants to book a flight. In every intent you can set the action name this is a field in Dialogflow, this string is what you listen for in botman, combined with the middleware you need to add which you see in the docs for botman and dialogflow.

The reply handling is then just inside BotMan. It would be possible from Dialogflow as well but recommended is using normal reply options from botman.

LiamRoels commented 5 years ago

$botman->hears('input.welcome', function(BotMan $bot) { //you action })->middleware($dialogflow);

Is it some example like this you are looking for? Here input.welcome is the action name I filled in on the Actions and parameters bit of a Dialogflow intent

Aramis-Delg commented 5 years ago

Hi, I still having questions about this; I don't know If I should use my client or developer api token, and is my intent's name is auto I should call it 'input.auto'. by the time botman is not listening to middleware from Dialogflow.

christophrumpel commented 5 years ago

Hey, both are working but I would use the Client access token because you can refresh that in the DialogFlow settings if you need at some point.

Also, you have to listen to the action name you provide. So when you call it auto. You need to listen to auto.

I hope this helps. Also, I will close this issue here. Please use the BotMan Slack channel if you need help.

kints commented 5 years ago

Hi! I'm working on an integration for Dialogflow also, I had response on dialogflow, however I have an error on Laravel.log, I don't know what I'm missing, please give me a hint

botman.php code:

<?php
use BotMan\BotMan\BotMan;
use App\Http\Controllers\BotManController;
use BotMan\BotMan\Middleware\ApiAi;

$botman = resolve('botman');

$dialogflow = ApiAi::create('token')->listenForAction();
$botman->middleware->received($dialogflow);
$botman->hears('autos.tipos', function (Botman $bot){
  $extras = $bot->getMessage()->getExtras();
  $apiReply = $extras['apireply'];
  $apiAction = $extras['apiAction'];
  $apiIntent = $extras['apiIntent'];

  $bot->reply($apiReply);
})->middleware($dialogflow);

laravel.log

[2019-03-16 02:43:37] local.ERROR: The Response content must be a string or object implementing toString(), "boolean" given. {"exception":"[object] (UnexpectedValueException(code: 0): The Response content must be a string or object implementing toString(), \"boolean\" given. at /home/ravisacars/jacobv1/vendor/symfony/http-foundation/Response.php:394) [stacktrace]

0 /home/ravisacars/jacobv1/vendor/symfony/http-foundation/Response.php(202): Symfony\Component\HttpFoundation\Response->setContent(false)

1 /home/ravisacars/jacobv1/vendor/symfony/http-foundation/Response.php(223): Symfony\Component\HttpFoundation\Response->__construct(false, 200, Array)

2 /home/ravisacars/jacobv1/vendor/botman/driver-web/src/WebDriver.php(196): Symfony\Component\HttpFoundation\Response::create(false, 200, Array)

3 /home/ravisacars/jacobv1/vendor/botman/botman/src/BotMan.php(417): BotMan\Drivers\Web\WebDriver->messagesHandled()

4 /home/ravisacars/jacobv1/app/Http/Controllers/BotManController.php(20): BotMan\BotMan\BotMan->listen()

5 [internal function]: App\Http\Controllers\BotManController->handle()

6 /home/ravisacars/jacobv1/vendor/laravel/framework/src/Illuminate/Routing/Controller.php(54): call_user_func_array(Array, Array)

7 /home/ravisacars/jacobv1/vendor/laravel/framework/src/Illuminate/Routing/ControllerDispatcher.php(45): Illuminate\Routing\Controller->callAction('handle', Array)

8 /home/ravisacars/jacobv1/vendor/laravel/framework/src/Illuminate/Routing/Route.php(212): Illuminate\Routing\ControllerDispatcher->dispatch(Object(Illuminate\Routing\Route), Object(App\Http\Controllers\BotManController), 'handle')

9 /home/ravisacars/jacobv1/vendor/laravel/framework/src/Illuminate/Routing/Route.php(169): Illuminate\Routing\Route->runController()

10 /home/ravisacars/jacobv1/vendor/laravel/framework/src/Illuminate/Routing/Router.php(679): Illuminate\Routing\Route->run()

11 /home/ravisacars/jacobv1/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php(30): Illuminate\Routing\Router->Illuminate\Routing\{closure}(Object(Illuminate\Http\Request))

12 /home/ravisacars/jacobv1/vendor/laravel/framework/src/Illuminate/Routing/Middleware/SubstituteBindings.php(41): Illuminate\Routing\Pipeline->Illuminate\Routing\{closure}(Object(Illuminate\Http\Request))

13 /home/ravisacars/jacobv1/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(151): Illuminate\Routing\Middleware\SubstituteBindings->handle(Object(Illuminate\Http\Request), Object(Closure))

14 /home/ravisacars/jacobv1/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php(53): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))

15 /home/ravisacars/jacobv1/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/VerifyCsrfToken.php(75): Illuminate\Routing\Pipeline->Illuminate\Routing\{closure}(Object(Illuminate\Http\Request))

16 /home/ravisacars/jacobv1/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(151): Illuminate\Foundation\Http\Middleware\VerifyCsrfToken->handle(Object(Illuminate\Http\Request), Object(Closure))

17 /home/ravisacars/jacobv1/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php(53): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))

18 /home/ravisacars/jacobv1/vendor/laravel/framework/src/Illuminate/View/Middleware/ShareErrorsFromSession.php(49): Illuminate\Routing\Pipeline->Illuminate\Routing\{closure}(Object(Illuminate\Http\Request))

19 /home/ravisacars/jacobv1/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(151): Illuminate\View\Middleware\ShareErrorsFromSession->handle(Object(Illuminate\Http\Request), Object(Closure))

20 /home/ravisacars/jacobv1/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php(53): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))

21 /home/ravisacars/jacobv1/vendor/laravel/framework/src/Illuminate/Session/Middleware/StartSession.php(63): Illuminate\Routing\Pipeline->Illuminate\Routing\{closure}(Object(Illuminate\Http\Request))

22 /home/ravisacars/jacobv1/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(151): Illuminate\Session\Middleware\StartSession->handle(Object(Illuminate\Http\Request), Object(Closure))

23 /home/ravisacars/jacobv1/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php(53): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))

24 /home/ravisacars/jacobv1/vendor/laravel/framework/src/Illuminate/Cookie/Middleware/AddQueuedCookiesToResponse.php(37): Illuminate\Routing\Pipeline->Illuminate\Routing\{closure}(Object(Illuminate\Http\Request))

25 /home/ravisacars/jacobv1/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(151): Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse->handle(Object(Illuminate\Http\Request), Object(Closure))

26 /home/ravisacars/jacobv1/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php(53): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))

27 /home/ravisacars/jacobv1/vendor/laravel/framework/src/Illuminate/Cookie/Middleware/EncryptCookies.php(66): Illuminate\Routing\Pipeline->Illuminate\Routing\{closure}(Object(Illuminate\Http\Request))

28 /home/ravisacars/jacobv1/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(151): Illuminate\Cookie\Middleware\EncryptCookies->handle(Object(Illuminate\Http\Request), Object(Closure))

29 /home/ravisacars/jacobv1/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php(53): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))

30 /home/ravisacars/jacobv1/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(104): Illuminate\Routing\Pipeline->Illuminate\Routing\{closure}(Object(Illuminate\Http\Request))

31 /home/ravisacars/jacobv1/vendor/laravel/framework/src/Illuminate/Routing/Router.php(681): Illuminate\Pipeline\Pipeline->then(Object(Closure))

32 /home/ravisacars/jacobv1/vendor/laravel/framework/src/Illuminate/Routing/Router.php(656): Illuminate\Routing\Router->runRouteWithinStack(Object(Illuminate\Routing\Route), Object(Illuminate\Http\Request))

33 /home/ravisacars/jacobv1/vendor/laravel/framework/src/Illuminate/Routing/Router.php(622): Illuminate\Routing\Router->runRoute(Object(Illuminate\Http\Request), Object(Illuminate\Routing\Route))

34 /home/ravisacars/jacobv1/vendor/laravel/framework/src/Illuminate/Routing/Router.php(611): Illuminate\Routing\Router->dispatchToRoute(Object(Illuminate\Http\Request))

35 /home/ravisacars/jacobv1/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php(176): Illuminate\Routing\Router->dispatch(Object(Illuminate\Http\Request))

36 /home/ravisacars/jacobv1/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php(30): Illuminate\Foundation\Http\Kernel->Illuminate\Foundation\Http\{closure}(Object(Illuminate\Http\Request))

37 /home/ravisacars/jacobv1/vendor/fideloper/proxy/src/TrustProxies.php(57): Illuminate\Routing\Pipeline->Illuminate\Routing\{closure}(Object(Illuminate\Http\Request))

38 /home/ravisacars/jacobv1/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(151): Fideloper\Proxy\TrustProxies->handle(Object(Illuminate\Http\Request), Object(Closure))

39 /home/ravisacars/jacobv1/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php(53): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))

40 /home/ravisacars/jacobv1/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/TransformsRequest.php(31): Illuminate\Routing\Pipeline->Illuminate\Routing\{closure}(Object(Illuminate\Http\Request))

41 /home/ravisacars/jacobv1/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(151): Illuminate\Foundation\Http\Middleware\TransformsRequest->handle(Object(Illuminate\Http\Request), Object(Closure))

42 /home/ravisacars/jacobv1/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php(53): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))

43 /home/ravisacars/jacobv1/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/TransformsRequest.php(31): Illuminate\Routing\Pipeline->Illuminate\Routing\{closure}(Object(Illuminate\Http\Request))

44 /home/ravisacars/jacobv1/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(151): Illuminate\Foundation\Http\Middleware\TransformsRequest->handle(Object(Illuminate\Http\Request), Object(Closure))

45 /home/ravisacars/jacobv1/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php(53): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))

46 /home/ravisacars/jacobv1/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/ValidatePostSize.php(27): Illuminate\Routing\Pipeline->Illuminate\Routing\{closure}(Object(Illuminate\Http\Request))

47 /home/ravisacars/jacobv1/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(151): Illuminate\Foundation\Http\Middleware\ValidatePostSize->handle(Object(Illuminate\Http\Request), Object(Closure))

48 /home/ravisacars/jacobv1/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php(53): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))

49 /home/ravisacars/jacobv1/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/CheckForMaintenanceMode.php(62): Illuminate\Routing\Pipeline->Illuminate\Routing\{closure}(Object(Illuminate\Http\Request))

50 /home/ravisacars/jacobv1/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(151): Illuminate\Foundation\Http\Middleware\CheckForMaintenanceMode->handle(Object(Illuminate\Http\Request), Object(Closure))

51 /home/ravisacars/jacobv1/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php(53): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))

52 /home/ravisacars/jacobv1/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(104): Illuminate\Routing\Pipeline->Illuminate\Routing\{closure}(Object(Illuminate\Http\Request))

53 /home/ravisacars/jacobv1/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php(151): Illuminate\Pipeline\Pipeline->then(Object(Closure))

54 /home/ravisacars/jacobv1/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php(116): Illuminate\Foundation\Http\Kernel->sendRequestThroughRouter(Object(Illuminate\Http\Request))

55 /home/ravisacars/public_html/index.php(55): Illuminate\Foundation\Http\Kernel->handle(Object(Illuminate\Http\Request))

56 {main}

"}

intents

thank you in advance Christoph, you're awesome !!!

speedygonzales77 commented 5 years ago

Hello all. After doing some debugging I got assisted by Liam in the Slack portal. Just in case you run into the same issue, the example from Kint above should work just fine. There is just a misspell. Change $extras['apireply']; for $extras['apiReply']; with capital R.

theoafactor commented 4 years ago

How can I use Dialogflow in Botman's conversation? I have been trying this all day. Thanks