/** * @param string $text * @param Context|null $context * @param array $queryParams * * @return mixed */ public function extractMeaning($text, Context $context = null, array $queryParams = []) { $query = array_merge($queryParams, ['q' => $text]); if (null !== $context && !$context->isEmpty()) { $query['context'] = json_encode($context); } $response = $this->client->get('/message', $query); return $this->decodeResponse($response); }
/** * @param string|resource $file * @param array|null $context * @param array $queryParams * * @return array|null */ public function extractMeaning($file, Context $context = null, array $queryParams = []) { if (!$file || !is_resource($file) && !is_readable($file)) { throw new \InvalidArgumentException('$file argument must be a readable file path or a valid resource'); } if (null !== $context && !$context->isEmpty()) { $queryParams['context'] = json_encode($context); } $file = is_resource($file) ? $file : fopen($file, 'r'); $response = $this->client->send('POST', '/speech', $file, $queryParams); return $this->decodeResponse($response); }
/** * @param string $sessionId * @param string|null $text * @param Context|null $context * * @return array */ public function converse($sessionId, $text = null, Context $context = null) { $query = ['session_id' => $sessionId]; if (!empty($text)) { $query['q'] = $text; } $body = null; // Don't send empty array if (null !== $context && !$context->isEmpty()) { $body = $context; } $response = $this->client->send('POST', '/converse', $body, $query); return $this->decodeResponse($response); }
function it_delegate_merge_execution($api, $actionMapping) { $api->converse('session_id', 'my text', Argument::any())->willReturn($this->stepData[Step::TYPE_MERGE]); $expectedContext = new Context(); $expectedContext->add('custom', 'value'); $actionMapping->merge('session_id', Argument::type(Context::class), $this->stepData[Step::TYPE_MERGE]['entities'])->willReturn($expectedContext); $api->converse('session_id', null, $expectedContext)->willReturn($this->stepData[Step::TYPE_STOP]); $actionMapping->stop('session_id', Argument::type(Context::class))->shouldBeCalled(); $this->converse('session_id', 'my text')->shouldReturn($expectedContext); }