/** * Return new thought based on given thought * @param \ChatterBotApi\ChatterBotTought $thought The previous thought * @return \ChatterBotApi\ChatterBotTought The new thought. * * @throws \Exception If response is empty (when input string is empty) */ public function thinkThought(ChatterBotThought $thought) { $this->vars['input'] = $thought->getText(); $response = Utils::post('http://www.pandorabots.com/pandora/talk-xml', $this->vars); $element = new SimpleXMLElement($response); $result = $element->xpath('//result/that/text()'); if (isset($result[0][0])) { return ChatterBotThought::make($result[0][0]); } else { throw new Exception('Empty Response'); } }
/** * Return new thought based on given thought * @param \ChatterBotApi\ChatterBotTought $thought The previous thought * @return \ChatterBotApi\ChatterBotTought The new thought. */ public function thinkThought(ChatterBotThought $thought) { $this->vars['stimulus'] = $thought->getText(); $data = http_build_query($this->vars); $dataToDigest = substr($data, 9, 20); $dataDigest = md5($dataToDigest); $this->vars['icognocheck'] = $dataDigest; $response = Utils::post($this->bot->getUrl(), $this->vars); $responseValues = explode("\r", $response); // $this->vars['??'] = Utils::stringAtIndex($responseValues, 0); $this->vars['sessionid'] = Utils::stringAtIndex($responseValues, 1); $this->vars['logurl'] = Utils::stringAtIndex($responseValues, 2); $this->vars['vText8'] = Utils::stringAtIndex($responseValues, 3); $this->vars['vText7'] = Utils::stringAtIndex($responseValues, 4); $this->vars['vText6'] = Utils::stringAtIndex($responseValues, 5); $this->vars['vText5'] = Utils::stringAtIndex($responseValues, 6); $this->vars['vText4'] = Utils::stringAtIndex($responseValues, 7); $this->vars['vText3'] = Utils::stringAtIndex($responseValues, 8); $this->vars['vText2'] = Utils::stringAtIndex($responseValues, 9); $this->vars['prevref'] = Utils::stringAtIndex($responseValues, 10); // $this->vars['??'] = Utils::stringAtIndex($responseValues, 11); $this->vars['emotionalhistory'] = Utils::stringAtIndex($responseValues, 12); $this->vars['ttsLocMP3'] = Utils::stringAtIndex($responseValues, 13); $this->vars['ttsLocTXT'] = Utils::stringAtIndex($responseValues, 14); $this->vars['ttsLocTXT3'] = Utils::stringAtIndex($responseValues, 15); $this->vars['ttsText'] = Utils::stringAtIndex($responseValues, 16); $this->vars['lineRef'] = Utils::stringAtIndex($responseValues, 17); $this->vars['lineURL'] = Utils::stringAtIndex($responseValues, 18); $this->vars['linePOST'] = Utils::stringAtIndex($responseValues, 19); $this->vars['lineChoices'] = Utils::stringAtIndex($responseValues, 20); $this->vars['lineChoicesAbbrev'] = Utils::stringAtIndex($responseValues, 21); $this->vars['typingData'] = Utils::stringAtIndex($responseValues, 22); $this->vars['divert'] = Utils::stringAtIndex($responseValues, 23); if ('' == Utils::stringAtIndex($responseValues, 16)) { throw new Exception('Empty Response'); } return ChatterBotThought::make(Utils::stringAtIndex($responseValues, 16)); }