forked from GeorgeNava/phpwebsocket
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathchatbot.demo.php
More file actions
25 lines (23 loc) · 1.12 KB
/
chatbot.demo.php
File metadata and controls
25 lines (23 loc) · 1.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
#!/php -q
<?php
// Run from command prompt > php -q chatbot.demo.php
include "websocket.class.php";
// Extended basic WebSocket as ChatBot
class ChatBot extends WebSocket{
function process($user,$msg){
$this->say("< ".$msg);
switch($msg){
case "hello" : $this->send($user->socket,"hello human"); break;
case "hi" : $this->send($user->socket,"zup human"); break;
case "name" : $this->send($user->socket,"my name is Multivac, silly I know"); break;
case "age" : $this->send($user->socket,"I am older than time itself"); break;
case "date" : $this->send($user->socket,"today is ".date("Y.m.d")); break;
case "time" : $this->send($user->socket,"server time is ".date("H:i:s")); break;
case "thanks": $this->send($user->socket,"you're welcome"); break;
case "bye" : $this->send($user->socket,"bye"); break;
default : $this->send($user->socket,$msg." not understood"); break;
}
}
}
$ws = new ChatBot("localhost",12345);
$ws->listen();