Pipedream Alexa Test 1
@raymondcamden
code:
data:privatelast updated:10 months ago
today
Build integrations remarkably fast!
You're viewing a public workflow template.
Sign up to customize, add steps, modify code and more.
Join 500,000+ developers using the Pipedream platform
steps.
trigger
HTTP API
Deploy to generate unique URL
This workflow runs on Pipedream's servers and is triggered by HTTP / Webhook requests.
steps.
verification
auth
to use OAuth tokens and API keys in code via theauths object
code
Write any Node.jscodeand use anynpm package. You can alsoexport datafor use in later steps via return or this.key = 'value', pass input data to your code viaparams, and maintain state across executions with$checkpoint.
async (event, steps) => {
1
2
3
4
5
6
7
8
9
10
11
12
13
14
}
15
import verifier from 'alexa-verifier'

let signaturechainurl = event.headers["signaturecertchainurl"];
let signature = event.headers["signature"];
let body = event.body;

try {
  await verifier(signaturechainurl, signature, JSON.stringify(body));
} catch(e) {
  console.log(JSON.stringify(e));
  $end("Failed verification.")
}
steps.
determineintent
auth
to use OAuth tokens and API keys in code via theauths object
code
Write any Node.jscodeand use anynpm package. You can alsoexport datafor use in later steps via return or this.key = 'value', pass input data to your code viaparams, and maintain state across executions with$checkpoint.
async (event, steps) => {
1
2
3
}
4
if(event.body.request.intent) this.intent = event.body.request.intent.name;
if(event.body.request.type == 'LaunchRequest') this.intent = 'AMAZON.HelpIntent';
steps.
hellohelpintent
auth
to use OAuth tokens and API keys in code via theauths object
code
Write any Node.jscodeand use anynpm package. You can alsoexport datafor use in later steps via return or this.key = 'value', pass input data to your code viaparams, and maintain state across executions with$checkpoint.
async (event, steps) => {
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
}
24
console.log('Intent:', steps.determineintent.intent);

if(steps.determineintent.intent !== 'AMAZON.HelpIntent') return;

var response = {
  "version": "1.0",
  "response" :{
    "shouldEndSession": true,
    "outputSpeech": {
      "type": "PlainText",
      "text": "I give you a completely scientifically driven, 100% accurate horoscope. Honest."
    }
  }
}

await $respond({
  status:200,
  immediate:true,
  body:response
});
$end();
steps.
stopintent
auth
to use OAuth tokens and API keys in code via theauths object
code
Write any Node.jscodeand use anynpm package. You can alsoexport datafor use in later steps via return or this.key = 'value', pass input data to your code viaparams, and maintain state across executions with$checkpoint.
async (event, steps) => {
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
}
22
if(!(steps.determineintent.intent === 'AMAZON.StopIntent' || steps.determineintent.intent === 'AMAZON.CancelIntent')) return;

var response = {
  "version": "1.0",
  "response" :{
    "shouldEndSession": true,
    "outputSpeech": {
      "type": "PlainText",
      "text": "Bye!"
    }
  }
}

await $respond({
  status:200,
  immediate:true,
  body:response
});
$end();
steps.
horoscopeintent
auth
to use OAuth tokens and API keys in code via theauths object
code
Write any Node.jscodeand use anynpm package. You can alsoexport datafor use in later steps via return or this.key = 'value', pass input data to your code viaparams, and maintain state across executions with$checkpoint.
async (event, steps) => {
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
}
98

const { generateSlug } = await import('random-word-slugs');

const signs = ["Aries","Taurus","Gemini","Cancer","Leo","Virgo","Libra","Scorpio","Sagittarius","Capricorn","Aquarius","Pisces"];

function getAdjective() {
	return generateSlug(1, { 
    partsOfSpeech:['adjective'], 
    format: 'lower' })
}

function getNoun() {
	return generateSlug(1, { 
    partsOfSpeech:['noun'], 
    format: 'lower' })
}

function getSign() {
	return signs[randRange(0,signs.length-1)];
}


function getFinancialString() {
	let options = [
		"Today is a good day to invest. Stock prices will change. ",
		"Today is a bad day to invest. Stock prices will change. ",
		"Investments are a good idea today. Spend wisely before the " + getAdjective() + " " + getNoun() + " turns your luck! ",
		"Save your pennies! Your " + getNoun() + " is not a safe investment today. ",
		"Consider selling your " + getNoun() + " for a good return today. ",
		"You can buy a lottery ticket or a " + getNoun() + ". Either is a good investment. "
	];
	return options[randRange(1,options.length-1)];
}

function getRomanticString() {
	let options = [
		"Follow your heart like you would follow a "+getAdjective() + " " + getNoun() + ". It won't lead you astray. ",
		"You will fall in love with a " + getSign() + " but they are in love with their " + getNoun() + ". ",
		"Romance is not in your future today. Avoid it like a " + getAdjective() + " " + getNoun() + ". ",
		"Romance is blossoming like a " + getAdjective() + " " + getNoun() + "! ",
		"Avoid romantic engagements today. Wait for a sign - it will resemble a " +getAdjective() + " " + getNoun() + ". ",
		"Love is in the air. Unfortunately not the air you will be breathing. "
	];
	return options[randRange(1,options.length-1)];
}

function getRandomString() {
	var options = [
		"Avoid talking to a " + getSign() + " today. They will vex you and bring you a " + getNoun() + ". ",
		"Spend time talking to a " + getSign() + " today. They think you are a " + getNoun() + "! ",
		"Dont listen to people who give you vague advice about life or your " + getNoun() + ". ",
		"Today you need to practice your patience. And your piano. ",
		"Meet new people today. Show them your " + getNoun() + ". ",
		"Your spirits are high today - but watch our for a " + getAdjective() + " " + getNoun() + ". ",
		"Your sign is in the third phase today. This is important. ",
		"Your sign is in the second phase today. This is critical. ",
		"Something big is going to happen today. Or tomorrow. ",
		"Something something you're special and important something something." ,
		"A " + getAdjective() + " " + getNoun() + " will give you important advice today. ",
		"A " + getAdjective() + " " + getNoun() + " has it out for you today. ",
		"Last Tuesday was a good day. Today - not so much. ",
		"On the next full moon, it will be full. ",
		"Today is a bad day for work - instead focus on your " + getNoun() + ". ",
		"Today is a good day for work - but don't forget your " + getNoun() + ". ",
		"A dark stranger will enter your life. They will have a " + getAdjective() + " " + getNoun() + ". "
	];
	return options[randRange(1,options.length-1)];
}

function randRange(minNum, maxNum) {
	return (Math.floor(Math.random() * (maxNum - minNum + 1)) + minNum);
}


let horoscope = `
${getRandomString()} ${getFinancialString()} ${getRandomString()}
Your lucky numbers are ${randRange(1,10)}, ${randRange(1,10)}, and ${getNoun()}.
`;
	
var response = {
    "version": "1.0",
    "response" :{
      "shouldEndSession": true,
      "outputSpeech": {
        "type": "PlainText",
        "text": horoscope
        }
      }
  }

  await $respond({
    status:200,
    immediate:true,
    body:response
  })