Last active
February 11, 2018 11:14
-
-
Save r3-yamauchi/6f49e5c3bbdde5cc99678ae1f8b32ce1 to your computer and use it in GitHub Desktop.
これは https://blog.r3it.com/ に投稿する Alexa プッシュ通知に関する記事の受信例です。 https://blog.r3it.com/alexa-day-2018-73928e3b3923
This file contains 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
var handlers = { | |
'Messaging.MessageReceived': function() { | |
console.log("Messaging.MessageReceived", JSON.stringify(this.event)); | |
const message = this.event.request.message; | |
const apiAccessToken = this.event.context.System.apiAccessToken; | |
let date1 = new Date(); | |
date1.setMinutes(date1.getMinutes() + 30); | |
const requestBody = { | |
"displayInfo": { | |
"content": [{ | |
"locale": "en-US", | |
"toast": { | |
"primaryText": message.spokenOutput | |
}, | |
"title": message.notificationTitle, | |
"bodyItems": [{ | |
"primaryText": message.spokenOutput | |
}] | |
}] | |
}, | |
"referenceId": process.env.ALEXA_THIS_SKILL_ID, | |
"expiryTime": date1.toISOString(), | |
"spokenInfo": { | |
"content": [{ | |
"locale": "en-US", | |
"text": message.spokenOutput, | |
"ssml": `<speak>${message.spokenOutput}</speak> ` | |
}] | |
} | |
}; | |
const request_options = { | |
"Content-Type": "application/json; charset=UTF-8", | |
url: `https://api.amazonalexa.com/v2/notifications`, | |
method: "POST", | |
gzip: false, | |
headers: { | |
"Authorization": `Bearer ${apiAccessToken}` | |
}, | |
json: requestBody | |
}; | |
console.log("request_options", JSON.stringify(request_options)); | |
request(request_options, function(error, response, body) { | |
console.log("[/v2/notifications] error: ", JSON.stringify(error, null, 2)); | |
console.log("[/v2/notifications] response: ", JSON.stringify(response, null, 2)); | |
console.log("[/v2/notifications] body: ", JSON.stringify(body, null, 2)); | |
return callback(null, { | |
statusCode: response.statusCode, | |
body: JSON.stringify(response), | |
headers: { | |
"Content-Type": "application/json; charset=utf-8" | |
}, | |
}); | |
}); | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment