This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
app.intent('Play', async (conv: Conv, params: {search: string}) => { | |
// "Forest: Day" -> "forest day" | |
const search = params.search.toLowerCase() | |
const searchResults = [] | |
for (const track of conv.data.json.tracks) { | |
const title = track.track_title.replace(/:/g, '').toLowerCase() | |
const genres = track.track_genre.map((g: string) => g.toLowerCase()) | |
const tags = track.tags.map((t: string) => t.toLowerCase()) | |
if (title.indexOf(search) > -1) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
app.intent('Play', async (conv: Conv) => { | |
// TODO: Hardcode track data for prototyping | |
conv.ask(generateMediaResponse(track)) | |
conv.ask(getSuggestions(conv.data.json.tracks)) | |
}) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function generateMediaResponse(track: TabletopAudioTrack): MediaObject { | |
return new MediaObject({ | |
name: track.track_title, | |
url: track.link, | |
description: track.flavor_text, | |
image: new Image({ | |
url: track.large_image, | |
alt: `Track art for ${track.track_title!}` | |
}) | |
}) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
app.middleware(async (conv: Conv) => { | |
await cacheResults(conv) | |
}) | |
async function cacheResults(conv: Conv) { | |
if (!conv.data.json) { | |
const response = await fetch(tabletopAudioUrl) | |
const json: TabletopAudioResponse = await response.json() | |
conv.data.json = json | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
app.middleware(async (conv: Conv) => { | |
await cacheResults(conv) | |
}) | |
async function cacheResults(conv: Conv) { | |
if (!conv.data.json) { | |
const response = await fetch(tabletopAudioUrl) | |
const json: TabletopAudioResponse = await response.json() | |
conv.data.json = json | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
async function cacheResults(conv: Conv) { | |
const response = await fetch(tabletopAudioUrl) | |
const json: TabletopAudioResponse = await response.json() | |
conv.data.json = json | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
interface TabletopAudioResponse { | |
tracks: TabletopAudioTrack[] | |
} | |
interface TabletopAudioSession { | |
json: TabletopAudioResponse, | |
currentTrack: TabletopAudioTrack | |
} | |
interface TabletopAudioTrack { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="UTF-8"?> | |
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | |
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | |
<modelVersion>4.0.0</modelVersion> | |
<parent> | |
<groupId>org.springframework.boot</groupId> | |
<artifactId>spring-boot-starter-parent</artifactId> | |
<version>2.1.2.RELEASE</version> | |
<relativePath/> <!-- lookup parent from repository --> | |
</parent> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@SpringBootApplication | |
public class ActionsApplication { | |
private static final Logger LOG = LoggerFactory.getLogger(SillyNameMakerApp.class); | |
private final App actionsApp = new SillyNameMakerApp(); | |
@RestController | |
class ActionsController { | |
@GetMapping("/") | |
String serveAck() { | |
return "App is listening but requires valid POST request to respond with Action response."; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Connect to Cloud Firestore | |
const admin = require('firebase-admin'); | |
admin.initializeApp(); | |
const db = admin.firestore(); | |
db.settings({timestampsInSnapshots: true}); | |
app.onSync(async (body, headers) => { | |
const userEmail = await getEmail(headers); | |
const userDoc = await db.collection('users').doc(userEmail).get(); |