Skip to content

Instantly share code, notes, and snippets.

@issacg
Created December 26, 2018 07:52
Show Gist options
  • Save issacg/ad2f498cdde0171b17148bc13250bc20 to your computer and use it in GitHub Desktop.
Save issacg/ad2f498cdde0171b17148bc13250bc20 to your computer and use it in GitHub Desktop.
/*
Copyright 2018 Issac Goldstand
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
const CandlelightingIntentHandler = {
canHandle(handlerInput) {
return handlerInput.requestEnvelope.request.type === 'IntentRequest'
&& handlerInput.requestEnvelope.request.intent.name === 'CandleLightingIntent';
},
async handle(handlerInput) {
try {
const token = handlerInput.requestEnvelope.context.System.user.accessToken;
const response = await request('https://hass.io.public/api/states/sensor.shabbat', {
json: true,
auth: {bearer: token}
});
const time = new Date(response.attributes.candles);
const speechText = `Candle lighting for ${response.state} is at ${time.getHours()-12}:${time.getMinutes()} <say-as interpret-as="spell-out">PM</say-as>`;
const displayHeading = response.attributes.hebrew;
const displayText = `Candle lighting ${time.getHours()}:${time.getMinutes()}`;
return handlerInput.responseBuilder
.speak(speechText)
.withSimpleCard(displayHeading, displayText)
.getResponse();
} catch (e) {
console.error(e.stack);
return handlerInput.responseBuilder
.speak('Sorry. I ran in to a problem. Check the error logs for more details')
.withSimpleCard('Error', 'Sorry. I ran in to a problem')
.getResponse();
}
},
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment