use BotMan\BotMan\BotMan;
use BotMan\BotMan\Messages\Incoming\Answer;
public function handle()
{
$botman=app("botman");
$botman->hears("{message}",function($botman,$message)
{
if($message=="hi")
{
$this->askName($botman);
}
else
{
$botman->reply("kindly write hi to start the talk");
}
});
$botman->listen();
}
public function askName($botman)
{
$botman->ask("Hello what is your name",function(Answer $answer)
{
$name=$answer->getText();
$this->say("Nice to meet you"." ".$name);
});
}
Here is what the above code is Doing:
1. We are creating a function called handle() which will be called when the bot is started.
2. We are creating a variable called $botman which will be used to create a new instance of BotMan.
3. We are using the hears() method to listen to the messages sent by the user.
4. We are using the ask() method to ask the user for his/her name.
5. We are using the say() method to reply to the user.
Now, we need to create a route for the above controller.
class m150811_220037_add_position_column_to_post_table extends Migration { public function up() { $this->addColumn(‘post’, ‘position’, $this->integer()); } public function down() { $this->dropColumn(‘post’, ‘position’); } } Here is what the above code is Doing: 1. We’re adding a new column called position to the post table. 2. The position column is an integer. 3. If we want to remove the…
@isset($name) {{‘name is set!’}} @endisset Here is what the above code is Doing: 1. The @isset directive checks if the $name variable is set. 2. If the $name variable is set, the code inside the @isset directive will be executed. 3. If the $name variable is not set, the code inside the @isset directive will…
Here is what the above code is Doing: 1. It’s importing the Flask class from the flask module. 2. It’s creating an instance of the Flask class. The first argument is the name of the application’s module or package. If you are using a single module (as in this example), you should use __name__ because…
// Page containing a form: Your name : // myaction.php Hello Here is what the above code is Doing: 1. The first line of code is creating a form. 2. The form has two fields: name and submit. 3. The form is submitted to the page myaction.php. 4. The form uses the POST method. 5….
$dayofweek = date(‘w’, strtotime($date)); $result = date(‘Y-m-d’, strtotime(($day – $dayofweek).’ day’, strtotime($date))); Here is what the above code is Doing: 1. Get the day of the week for the given date. 2. Subtract the day of the week from the day of the month. 3. Use the result from #2 to get the date of…