Google Home per Webhook ohne Zusätze

Hi ich bin auf eine gute Anleitung gestolpert :

Send & Recieve | PHP & JSON | Google Home Developer Tutorial - YouTube

Leider will es aber bei mir nicht klappen…

Ich bekomme folgende Fehlermeldung im Simulator:

UnparseableJsonResponse
API Version 2: Failed to parse JSON response string with ‚INVALID_ARGUMENT‘ error: „: Cannot find field.“.

Ich weis nicht wo der Fehler ist, kann mich jemand unterstützen ?

Hallo drapple,
ich habe es auch mal probiert.
Ich bin nun soweit gekommen, dass der webhook in ips ankommt.

Allerdings hänge ich nun daran, wie ich das angekommene weiter verarbeiten kann.

Ich habe diesen Code im ips webhook drin:

<?
//OG Code by: Bruno_Gastaldi @ https://discuss.api.ai/t/webhook-in-php-example/229/8
//Modified by: Kevin.
header('Content-Type: application/json');
function processMessage($update) { 
if($update["result"]["action"] == ""){  
//Create File. 
$fp = file_put_contents( 'request.log', $update["result"]["parameters"]["msg"] ); 
//Return response. 
sendMessage(array(  
"source" => $update["result"]["source"],  
"speech" => $update["result"]["parameters"]["msg"], 
"displayText" => ".........TEXT HERE...........", 
"contextOut" => array()   
));
    }
}
function sendMessage($parameters) {
$req_dump = print_r( $parameters, true );
$fp = file_put_contents( 'reques4.log', $req_dump );
header('Content-Type: application/json'); 
echo json_encode($parameters);
}
$update_response = file_get_contents("php://input");
$update = json_decode($update_response, true);
if (isset($update["result"]["action"])) {
processMessage($update);
}

Hast Du eine Idee wie man den gesprochenen text in einen case bekommt?

Hi ich bin auch weiter gekommen :slight_smile:

Ich finde es nur unbenutzbar, das man erst „Mit AppName sprechen“ sagen muss und warten und dann erst den Befehl absetzten kann :frowning:

Geht das nicht besser ? Bei Alexa kann mit das in einem Satz sagen, bei ghome geht das nicht :frowning:

Ja ist einfach das gesprochene auszuwerten:

So bekomme ich den Text raus:

$text=$update[„result“][„parameters“][„msg“][„0“];

So wird aus dem Text ein Array :

$spokenWords=explode(" ", $text);

Und so werte ich aus:
//************************************** Kino *****************************
case ( in_array(‚kino‘, $spokenWords)):

if (in_array(‚an‘, $spokenWords))

 {     
  $response = "Kinomodus aktiviert";

  IPS_RunScript(29007 /*[Räume\Wohnzimmer\Wohnzimmer Leinwand\Wohnzimmer Leinwand\power]*/);
	   }
	   
	   
	   elseif (in_array('aus',  $spokenWords))
{
	$response = 'Kinomodus deaktiviert...';

	//HM_WriteValueFloat( 35876    , "LEVEL", 1.0);
IPS_RunScript(29007 /*[Räume\Wohnzimmer\Wohnzimmer Leinwand\Wohnzimmer Leinwand\power]*/);


} 
	   
	   else 
{ // nach "Switch" kein Schlüsselwort gefunden
	$response = 'Keine Ahnung was du machen willst, versuche es noch einmal !';
}

break;

Also man kann es etwas abkürzen.
In Google Home eine Verknüpfung anlegen.
z.B. so


Allerdings bleibt das warten nicht erspart.

Ja ist aber auch so blöd…

Es muss doch besser gehen ;-(

Könntest Du bitte dein komplettes Webhook Script mal hier rein stellen?
Es führt bei mir schon mal Aktionen aus, aber die Response kommt nicht an.

Sorry klar, das muss zum Schluss noch rein:

processMessage($update,"$response");

function processMessage($update, $antwort) {
if($update[„result“][„action“] == „“){
sendMessage(array(
„source“ => $update[„result“][„source“],
„speech“ => $antwort,
„displayText“ => $antwort,
„contextOut“ => array()
));
}
}

Schau dir das mal an :wink:

Google Assistant / Home Integration - Seite 5