Skip to content

Instantly share code, notes, and snippets.

@giovanemachado
Last active March 1, 2020 16:36
Show Gist options
  • Save giovanemachado/48ed5a75d0387c85e03b99e53fd96739 to your computer and use it in GitHub Desktop.
Save giovanemachado/48ed5a75d0387c85e03b99e53fd96739 to your computer and use it in GitHub Desktop.
Código utilizado no tutorial - final
<?php
/**
* BEM VINDO
*
* Esse é o Endpoint para uma Skill de exemplo na Alexa.
* Dúvidas, sugestões ou uma conversa aberta, por favor me encontre no Twitter: @giovanenott
*
* @author: Giovane Machado
*/
// A requisição traz conteúdo em JSON, então nós transformamos em um belo array utilizável
$arrContent = json_decode(file_get_contents("php://input"), TRUE);
// Se você der uma olhada completa no $arrContent, verá que há muitas informações úteis. Pegaremos agora o tipo da requisição.
$strRequestType = $arrContent["request"]["type"];
switch ($strRequestType) {
case "LaunchRequest":
$arrResponse = [
"version" => "1.0",
"response" => [
"outputSpeech" => [
"type" => "PlainText",
"text" => "Olá, bem vindo ao nosso tutorial. Você pode me dizer seu nome?"
],
"shouldEndSession" => false
]
];
break;
case "IntentRequest":
// Pega o nome da intenção, e ainda pega o valor do slotNome
$strIntentName = $arrContent["request"]["intent"]["name"];
$strSlotNome = $arrContent["request"]["intent"]["slots"]["slotNome"]["value"];
if ($strIntentName == "falandoNome") {
$arrResponse = [
"version" => "1.0",
"response" => [
"outputSpeech" => [
"type" => "PlainText",
"text" => "Entendi. Esse foi seu primeiro passo " . $strSlotNome . ", parabéns."
],
"shouldEndSession" => true
]
];
}
break;
}
// Prepara e responde a requisição, no formato exigido pela Amazon
header('Content-Type: application/json');
echo json_encode($arrResponse);
die();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment