Skip to content
This repository has been archived by the owner on Jan 2, 2023. It is now read-only.

MalformedResponse: the first element must be a 'simple_response', a 'structured_response' or a 'custom_response' #15

Open
bit111 opened this issue Dec 15, 2018 · 1 comment

Comments

@bit111
Copy link

bit111 commented Dec 15, 2018

Hello,
I tried to use this lib to simply print a BasicCard response but I have the following error:
_MalformedResponse final_response.rich_response: the first element must be a 'simple_response', a 'structured_response' or a 'custom_response'. _

And this is the code I used:

<?php

require './vendor/autoload.php';

use Dialogflow\WebhookClient;

use Dialogflow\Action\Responses\SimpleResponse;
use Dialogflow\Action\Responses\BasicCard;
/*
use Dialogflow\Action\Responses\Image;

use Dialogflow\Action\Questions\Carousel;
use Dialogflow\Action\Questions\Carousel\Option;

use \Dialogflow\RichMessage\Image;
*/


$agent = new WebhookClient(json_decode(file_get_contents('php://input'),true));

if ('question_intercept'==$agent->getIntent()) 
{
	$conv = $agent->getActionConversation();

	$question = $agent->getParameters()['questionValue'];
	if ($question == "picture")
	{
		$conv->close(BasicCard::create()
		    ->title('This is a title')
		    ->formattedText('This is a subtitle')
		    ->image('https://picsum.photos/400/300')
		    ->button('This is a button', 'https://docs.dialogflow.com/')
		);
				
		$agent->reply( $conv );
	}
	else
	{
		$agent->reply('You said: ' . $question);
	}
}
else
{
	$agent->reply('Failed');
}

header('Content-type: application/json');
echo json_encode($agent->render());

?>

@basiteaal
Copy link

@bit111 Probably related to the fact that you should also set a 'simple' response next to a rich message.
You are not looking after the device an end-user uses while working with the assistant. BasicCards are more into Google Actions rather than let's say Facebook Messenger etc.

My best guess is to use a simple response next to the basic card and it should work.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants