Closed skorotkiewicz closed 9 years ago
I hope I understand you question.
This library already supports being used by many concurrent users.
After creating a bot:
$factory = new ChatterBotFactory();
$bot = $factory->create(ChatterBotType::CLEVERBOT);
You just have to create a session per user (and serialize it into the session to be reused in each request of this user):
$botsession = $bot->createSession();
Here is something I wrote about this some time ago: https://code.google.com/p/chatter-bot-api/issues/detail?id=3#c5
I was concerned about something similar
function cleverbot($s,$userid) {
require 'cleverbot.php';
$factory = new ChatterBotFactory();
$bot1 = $factory->create(ChatterBotType::CLEVERBOT);
if ( file_exists('user' . $userid. '-cookie.txt') ) {
$bot1session = $bot1->LoadSession('user' . $userid. '-cookie.txt');
} else {
$bot1session = $bot1->createSession('user' . $userid. '-cookie.txt');
}
$s = $bot1session->think($s);
return $s;
}
The logic is almost fine, just do something like this:
function cleverbot($s,$userid) { require 'cleverbot.php'; $factory = new ChatterBotFactory(); $bot1 = $factory->create(ChatterBotType::CLEVERBOT); if ( file_exists('user' . $userid. '-cookie.txt') ) { $bot1session = ...unserialize content of file 'user' . $userid. '-cookie.txt' } else { $bot1session = $bot1->createSession('user' . $userid. '-cookie.txt'); } $s = $bot1session->think($s); ...serialize $bot1session into file 'user' . $userid. '-cookie.txt' return $s; }
Thanks, it works. :)
it is possible for cookies for separate user in Cleverbot? eg: user1_cookie.txt, user2_cookie.txt, user3_cookie.txt