Created
June 25, 2018 15:44
-
-
Save duylddev/c16479e62dc37586dfcb6c52c19c12d5 to your computer and use it in GitHub Desktop.
Chatbot
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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