Skip to content

Instantly share code, notes, and snippets.

View Fleker's full-sized avatar
💻
doing good things

Nick Fleker

💻
doing good things
View GitHub Profile
import MemoryBlock from "./memory-block";
import BitmapMemory from "./bitmap-memory";
import LinkedList from "./linked-list";
const PATH_VOLATILE = '.volatile'
// The FILE SYSTEM is an extension of a memory architecture which allows data
// to be stored in a globally accessible* tree of files and directories.
//
// * Restrictions on files may be present to prevent malicious access
const setSessionEntities = (conv: Conv) => {
// Create sets for each type of entity type
const trackTitles = new Set<string>()
const trackGenres = new Set<string>()
const trackTags = new Set<string>()
conv.data.json.tracks.forEach(track => {
trackTitles.add(track.track_title)
track.track_genre.forEach(genre => {
trackGenres.add(genre)
@Fleker
Fleker / index.ts
Created December 20, 2019 23:19
The new default welcome intent
app.intent('Default Welcome Intent', async (conv) => {
// … Welcome logic
conv.sessionEntities.send()
})
@Fleker
Fleker / index.ts
Last active December 20, 2019 23:25
The modified middleware
const setSessionEntities = (conv: Conv) => {
// Create sets for each type of entity type
const trackTitles = new Set<string>()
const trackGenres = new Set<string>()
const trackTags = new Set<string>()
@Fleker
Fleker / index.ts
Created December 20, 2019 23:18
The original middleware
type Conv = DialogflowConversation<TabletopAudioSession>
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()
@Fleker
Fleker / index.ts
Created December 20, 2019 23:17
Initialize session entities plugin
const { sessionEntitiesHelper } = require('actions-on-google-dialogflow-session-entities-plugin')
const app = dialogflow()
.use(sessionEntitiesHelper())
@Fleker
Fleker / index.ts
Created August 5, 2019 21:35
Improved welcome intent
app.intent('Default Welcome Intent', async (conv: Conv) => {
conv.ask(new SimpleResponse({
text: 'Welcome to Tabletop Audio! I can play a specific track, ' +
'or start playing based on a genre. What do you want to listen to?',
speech: `Welcome to Tabletop Audio! I can play a specific track ` +
`like ${conv.data.json.tracks[0].track_title}, or start playing based on a genre like ` +
`${conv.data.json.tracks[0].track_genre}. What do you want to listen to?`
}))
conv.ask(getSuggestions(conv.data.json.tracks))
})
@Fleker
Fleker / index.ts
Created August 5, 2019 21:34
Add newest tracks, and help intents
app.intent('New', (conv: Conv) => {
const newestTracks = conv.data.json.tracks.slice(0, 3)
conv.ask('The last three tracks added to Tabletop Audio are: ' +
newestTracks.map(track => track.track_title) +
'. What do you want to listen to?')
conv.ask(new Suggestions(...newestTracks.map(track => track.track_title)))
})
app.intent('Help', (conv: Conv) => {
conv.ask('Tabletop Audio is the premier advertising-free, free-to-use, and user-supported ' +
app.intent('actions.intent.MEDIA_STATUS', (conv: Conv) => {
const mediaStatus = conv.arguments.get('MEDIA_STATUS')
let response = 'Unknown media status received.'
if (mediaStatus && mediaStatus.status === 'FINISHED') {
response = 'Hope you enjoyed that song. What else do you want to listen to?';
}
conv.ask(response)
conv.ask(new Suggestions('Repeat'))
conv.ask(getSuggestions(conv.data.json.tracks))
})
app.intent('Current', (conv: Conv) => {
const track = conv.data.currentTrack
if (!track) {
conv.ask('Sorry, I don\'t think anything is playing. What do you want to listen to?')
conv.ask(getSuggestions(conv.data.json.tracks))
return
}
conv.ask(`This is ${track.track_title} from Tabletop Audio. ${track.flavor_text}`)
conv.ask(getSuggestions(conv.data.json.tracks))
})