Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
<?php
session_start();
date_default_timezone_set('America/Chicago');
// FUNCTIONS
require_once("/funcs/memcached.php");
require_once("/funcs/voice.php");
$now = time();
header('Content-Type: application/json;charset=UTF-8');
$data = new stdclass;
$data->speech = false;
$should_end_session = true;
$intent_name = $_GET['intent'];
// LATEST
if( $intent_name == "LatestAll" ) $data = intent_latest( "all" );
else if( $intent_name == "LatestSermon" ) $data = intent_latest( "sermon" );
else if( $intent_name == "LatestBibleClass" ) $data = intent_latest( "class" );
else if( $intent_name == "LatestDevo" ) $data = intent_latest( "devo" );
else if( $intent_name == "LatestArticle" ) $data = intent_latest( "article" );
// WHAT TO
if( $intent_name == "WhatToWatch" ) $data = intent_whatto( "watch" );
else if( $intent_name == "WhatToWatchSermon" ) $data = intent_whatto( "watch_sermon" );
else if( $intent_name == "WhatToWatchDevo" ) $data = intent_whatto( "watch_devo" );
else if( $intent_name == "WhatToWatchClass" ) $data = intent_whatto( "watch_class" );
else if( $intent_name == "WhatToTeachSermon" ) $data = intent_whatto( "teach_sermon" );
else if( $intent_name == "WhatToTeachDevo" ) $data = intent_whatto( "teach_devo" );
else if( $intent_name == "WhatToTeachClass" ) $data = intent_whatto( "teach_class" );
else if( $intent_name == "GoodBook" ) $data = intent_whatto( "read" );
// WHAT TO
if( $intent_name == "NextLesson" ) $data = intent_next( "lesson" );
else if( $intent_name == "NextLessons" ) $data = intent_next( "lessons" );
else if( $intent_name == "NextSermon" ) $data = intent_next( "sermon" );
else if( $intent_name == "NextBibleClass" ) $data = intent_next( "class" );
// POPULAR
if( $intent_name == "PopularSermon" ) $data = intent_popular( "sermon" );
else if( $intent_name == "PopularBibleClass" ) $data = intent_popular( "class" );
else if( $intent_name == "PopularDevo" ) $data = intent_popular( "devo" );
else if( $intent_name == "PopularArticle" ) $data = intent_popular( "article" );
else if( $intent_name == "PopularAll" ) $data = intent_popular( "all" );
else if( $intent_name == "MostViewed" ) $data = intent_popular( "viewed" );
// NOTHING
if( !$data->speech )
{
$should_end_session = false;
$data->speech = "I'm sorry I was not able to figure out what you wanted. Please try again.";
}
$response = new stdclass;
$response->reprompt = new stdclass;
$response->shouldEndSession = $should_end_session;
if( isset($data->item) AND $data->item )
{
$card = new stdclass;
$card->title = $data->item->title;
if( isset($data->item->subtitle) ) $card->subtitle = $data->item->subtitle;
$card->text = strip_tags($data->item->excerpt);
if( isset($data->item->image) AND $data->item->image )
{
$card->image = array();
$card->image['smallImageUrl'] = $data->item->image;
$card->image['largeImageUrl'] = $data->item->image;
}
$card->type = "Standard";
$response->card = $card;
}
$outputSpeech = new stdclass;
$outputSpeech->type = 'SSML';
$outputSpeech->ssml = "<speak>" . $data->speech . "</speak>";
$response->outputSpeech = $outputSpeech;
$response->reprompt->outputSpeech = $outputSpeech;
echo json_encode($response);
die;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment