Skip to content

Instantly share code, notes, and snippets.

@duylddev
Created June 25, 2018 15:44
Show Gist options
  • Save duylddev/c16479e62dc37586dfcb6c52c19c12d5 to your computer and use it in GitHub Desktop.
Save duylddev/c16479e62dc37586dfcb6c52c19c12d5 to your computer and use it in GitHub Desktop.
Chatbot
<?php
if(!isset($_REQUEST['action'])) {
die("Ahihi");
}
call_user_func('action_'.$_REQUEST['action']);
function action_xung_ho()
{
$gender = get('gender');
if($gender === 'female') {
return setAttribute('xung_ho', 'chị');
}
if($gender === 'male') {
return setAttribute('xung_ho', 'anh');
}
return setAttribute('xung_ho', 'bạn');
}
function setAttribute($key, $value)
{
return send(
[
'set_attributes' => [
$key => $value,
],
'messages' => []
]
);
}
function redirectToBlock($listBlockName)
{
if(is_string($listBlockName)) {
$listBlockName = [$listBlockName];
}
return send(
[
"redirect_to_blocks" => $listBlockName
]
);
}
function send($data)
{
header('Content-Type: application/json');
echo json_encode($data);
die();
}
function get($key, $default = null)
{
return isset($_REQUEST[$key]) ? $_REQUEST[$key] : $default;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment