Botman: use botman to search inside a database

Created on 20 Nov 2018  路  3Comments  路  Source: botman/botman

I want to use BotMan to create a chatbot that will search inside a databse starting from the user input.
Botman will hear for a phrase that will contain also the parameter to search like this: "search for name" or "search product by id" and similar. I'm reading about web driver but I'm not sure on how to setup it for this task. What is the correct configuration to achieve this and I need to write a middleware to manage this task?

Most helpful comment

You can create a tabel (hear FULLTEXT, reply TEXT)

$botman->hears('{hear}', function ($bot, $hear) {
    $results = DB::table('simple_conversation')
        ->selectRaw("*, MATCH (hear) AGAINST (? IN NATURAL LANGUAGE MODE) AS score", [$hear])
        ->whereRaw("MATCH (hear) AGAINST (? IN NATURAL LANGUAGE MODE)" , [$hear])
        ->havingRaw('score > ?', [0])
        ->orderByRaw('score DESC')
        ->get();
    if(count($results)>0){
        $bot->reply($results[0]->reply);
    }
    else{
        $bot->reply('I dont understand <b>'.$hear.'</b>');
        // send report
    }
});

How about this?

All 3 comments

you can use Dialogflow for this purpose

I want to use an offline solution, Dialogflow is great for natural language but will not be useful for the scope of my app.

You can create a tabel (hear FULLTEXT, reply TEXT)

$botman->hears('{hear}', function ($bot, $hear) {
    $results = DB::table('simple_conversation')
        ->selectRaw("*, MATCH (hear) AGAINST (? IN NATURAL LANGUAGE MODE) AS score", [$hear])
        ->whereRaw("MATCH (hear) AGAINST (? IN NATURAL LANGUAGE MODE)" , [$hear])
        ->havingRaw('score > ?', [0])
        ->orderByRaw('score DESC')
        ->get();
    if(count($results)>0){
        $bot->reply($results[0]->reply);
    }
    else{
        $bot->reply('I dont understand <b>'.$hear.'</b>');
        // send report
    }
});

How about this?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

hnguyen303 picture hnguyen303  路  5Comments

antonkomarev picture antonkomarev  路  5Comments

s4rrow picture s4rrow  路  5Comments

willsilvano picture willsilvano  路  4Comments

venkataadithan picture venkataadithan  路  5Comments