Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue using botman commands with wit ai commands (intents) #1382

Open
AbdullahKhdir opened this issue Sep 6, 2023 · 0 comments
Open

Issue using botman commands with wit ai commands (intents) #1382

AbdullahKhdir opened this issue Sep 6, 2023 · 0 comments

Comments

@AbdullahKhdir
Copy link

AbdullahKhdir commented Sep 6, 2023

  • BotMan Version: 2.8.2
  • PHP Version: 7.4
  • Messaging Service(s): Web
  • Cache Driver: FileSystemAdapter via SymfonyCache

Description:

When I add the wit.ai middleware and pass it as a parameter in the $bot->middleware->received($wit_middleware)

I listen all the hears commands inside of a group function passing the wit middleware as a value for the key 'middleware'

$botman->group(['middleware' => $wit_middleware], function ($botman_object) {
    //? incident_create is an intent in wit.ai
    $botman_object->hears('incident_create', function (BotMan $bot) {
        $user         = $bot->getUser();
        $message = $bot->getMessage()->getExtras()['entities'];
        $message = $message['incident_create:incident_create'][0]['value'];
        $bot->reply($message);
    });
});

and I have a normal listened command

$botman->hears('conversation', function ($bot) {
    $bot->startConversation(new IncidentConversation($bot));
});

and lastly I have a fallback

//? Fallback
$botman->fallback(function (BotMan $bot) {
    //? The fallback can access the heard middleware information like getExtras
    $user    = $bot->getMessage()->getExtras('user');
    $date    = $bot->getMessage()->getExtras('date');
    $message = $bot->getMessage()->getText();

    $bot->reply('On '. $date . ', the message provided from "'.$user. '" could not be processed!');
    $bot->reply('Original message: "'. $message. '"');
});

The problem is when I send a command that is not listened on wit.ai but on botman like the command conversation
then the matching function in wit middleware matches the pattern as if I have sent the wit.ai command instead.

How can I implement local commands with wit.ai commands, or should all the commands go directly to wit.ai and therefor local commands cannot be used locally when wit.ai is used ?

Steps To Reproduce:

1-Added wit middleware and configured it with the token and added it using received
$botman->middleware->received($wit_middleware);

2-Added a command that is bound to the wit middleware using group

$botman->group(['middleware' => $wit_middleware], function ($botman_object) {
    //? incident_create is an intent in wit.ai
    $botman_object->hears('incident_create', function (BotMan $bot) {
        $user         = $bot->getUser();
        $message = $bot->getMessage()->getExtras()['entities'];
        $message = $message['incident_create:incident_create'][0]['value'];
        $bot->reply($message);
    });
});

3-Added a normal command using botman

$botman->hears('conversation', function ($bot) {
    $bot->startConversation(new IncidentConversation($bot));
});

4-Added a fallback

//? Fallback
$botman->fallback(function (BotMan $bot) {
    //? The fallback can access the heard middleware information like getExtras
    $user    = $bot->getMessage()->getExtras('user');
    $date    = $bot->getMessage()->getExtras('date');
    $message = $bot->getMessage()->getText();

    $bot->reply('On '. $date . ', the message provided from "'.$user. '" could not be processed!');
    $bot->reply('Original message: "'. $message. '"');
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant