Skip to content

Commit

Permalink
docs: adding reminders API Javascript code sample (#541)
Browse files Browse the repository at this point in the history
* Adding Reminders API Javascript Code Sample
  • Loading branch information
RoyCodes authored and tianrenz committed Apr 19, 2019
1 parent 884a904 commit f4d46c7
Showing 1 changed file with 60 additions and 0 deletions.
60 changes: 60 additions & 0 deletions docs/en/Calling-Alexa-Service-APIs.rst
Original file line number Diff line number Diff line change
Expand Up @@ -602,3 +602,63 @@ Type Definition
getReminders(): Promise<services.reminderManagement.GetRemindersResponse>;
createReminder(reminderRequest: services.reminderManagement.ReminderRequest): Promise<services.reminderManagement.ReminderResponse>;
}
Code Sample
-----------

The following example shows a request handler that creates an instance of the ``ReminderManagementServiceClient`` and creates a new reminder.

.. code-block:: javascript
const CreateReminderIntent = {
canHandle(handlerInput) {
const { request } = handlerInput.requestEnvelope;
return request.type === 'IntentRequest' && request.intent.name === 'CreateReminderIntent';
},
async handle(handlerInput) {
const { requestEnvelope, serviceClientFactory, responseBuilder } = handlerInput;
const consentToken = requestEnvelope.context.System.user.permissions
&& requestEnvelope.context.System.user.permissions.consentToken;
if (!consentToken) {
return responseBuilder
.speak('Please enable Reminder permissions in the Amazon Alexa app.')
.withAskForPermissionsConsentCard(['alexa::alerts:reminders:skill:readwrite'])
.getResponse();
}
try {
const speechText = "Great! I've scheduled a reminder for you.";
const ReminderManagementServiceClient = serviceClientFactory.getReminderManagementServiceClient();
const reminderPayload = {
"trigger": {
"type": "SCHEDULED_RELATIVE",
"offsetInSeconds": "30",
"timeZoneId": "America/Los_Angeles"
},
"alertInfo": {
"spokenInfo": {
"content": [{
"locale": "en-US",
"text": "walk the dog"
}]
}
},
"pushNotification": {
"status": "ENABLED"
}
};
await ReminderManagementServiceClient.createReminder(reminderPayload);
return responseBuilder
.speak(speechText)
.getResponse();
} catch (error) {
console.error(error);
return responseBuilder
.speak('Uh Oh. Looks like something went wrong.')
.getResponse();
}
}
};

0 comments on commit f4d46c7

Please sign in to comment.