Generate commands from MySQL Table

Open
#97 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
20/100
Issue type
Bug
Clarity
Needs clarification
Activity status
Stale
Tech stack
mysql, php
Domain
backend, databases

Research direction

Start with the inline PHP script in the issue, especially the MySQL fetch loop and the callback passed to botman->hears. Compare this flow with the BotMan command and callback documentation; the issue is done only when each generated command produces its intended row-specific response, but the expected implementation is not specified.

Written by the indexing model from the issue text.

Description

Hi!

First off, thank you for this framework! I have been building a chatbot with some JS libraries and really wanted a way to protect some of the clever coding I have done. This is a fantastic solution.

One of my current goals to use my nice GUI CRUD editor to build out my conversations.
The script below connects to a Database and creates a command for each row in the table.

However, every response is equal to the last row's response value. Can anyone provide me with a hint on what I should be googling to find a solution? Right now I am focused on Variable Scopes.

Cheers!

Brandon

<?php
use App\Http\Controllers\BotManController;


$servername = "localhost";
$username = "USR";
$password = "PASS";
$dbname = "DB";



$botman = resolve('botman');



// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
} 

$sql = "SELECT id, command, responce, function FROM commands_general";
$result = $conn->query($sql);

if ($result->num_rows > 0) {
    // output data of each row
    while($row = $result->fetch_assoc()) {
     //   echo "<br> id: ". $row["id"]. " - Command: ". $row["command"]. " " . $row["responce"] . "<br>";
     $command = $row["command"];
     $GLOBALS['responce'. $row["id"]] = $row["responce"];
     $GLOBALS['id'] = $row["id"];
       
    $botman->hears($command, function ($bot) {
      global $id;

     // global $responce.$x;
        $bot->reply('heard you '.$id);  
        $id ++;  
});
    }
} else {
    echo "0 results";
}

$conn->close();

Dominant language
No language data
Stars
33
Forks
49
PR merge metrics
No merged PRs in 30d

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from botman/docs

All issues in botman/docs

Similar issues

More Backend & API Design issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.