4

I want to create push notifications to my Alexa Devide. Due the push notification program is closed I am trying to create reminders. The final idea is to create an Azure Function with this code and being called when a TFS Build faild.

I'm using Alexa.NET and Alexa.NET.Reminders from a console application, already have and Alexa Skill with all the permissions granted, in the Alexa portal and in the mobile app.

Everything seems to work nice until I try to read the reminders in my account, when get an exception "Invalid Bearer Token"

this is the code:

[Fact]
    public async Task SendNotificationTest()
    {

        var clientId = "xxxx";
        var clientSecret = "yyyy";

        var alexaClient = clientId;
        var alexaSecret = clientSecret;

        var accessToken = new Alexa.NET.AccessTokenClient(Alexa.NET.AccessTokenClient.ApiDomainBaseAddress);
        var token = await accessToken.Send(alexaClient, alexaSecret);

        var reminder = new Reminder
        {
            RequestTime = DateTime.UtcNow,
            Trigger = new RelativeTrigger(12 * 60 * 60),
            AlertInformation = new AlertInformation(new[] { new SpokenContent("test", "en-GB") }),
            PushNotification = PushNotification.Disabled
        };

        var total = JsonConvert.SerializeObject(reminder);
        var client = new RemindersClient("https://api.eu.amazonalexa.com", token.Token);

        var alertList = await client.Get();

        foreach (var alertInformation in alertList.Alerts)
        {
            Console.WriteLine(alertInformation.ToString());
        }

        try
        {
            var response = await client.Create(reminder);
        }
        catch (Exception ex)
        {
            var x = ex.Message;
        }
    }

Are there any examples to get the access token? Am I missing a step in the process?

Thanks in advance.

ssanga
  • 335
  • 3
  • 11

1 Answers1

1

N.B. The reminders client requires that you have a skill with reminders persmission enabled, and the user must have given your skill reminders permission (even if its your development account)

Creating a reminder

using Alexa.NET.Response
using Alexa.NET.Reminders
....
var reminder = new Reminder
{
    RequestTime = DateTime.UtcNow,
    Trigger = new RelativeTrigger(12 * 60 * 60),
    AlertInformation = new AlertInformation(new[] { new SpokenContent("it's a test", "en-GB") }),
    PushNotification = PushNotification.Disabled
};
var client = new RemindersClient(skillRequest);
var alertDetail = await client.Create(reminder);
Console.WriteLine(alertDetail.AlertToken);

Retrieving Current Reminders

// Single reminders can be retrieved with client.Get(alertToken)
var alertList = await client.Get();
foreach(var alertInformation in alertList.Alerts)
{
  //Your logic here
}

Deleting a Reminder

await client.Delete(alertToken);
Ahmad
  • 252
  • 1
  • 11
  • Hi Ahmad, thank you for your help. My principal issue is connecting the client with the proper token. I haven´t found any example to get the token properly and in my example I have an exception when the clients try to connect. I have already given permissions both the skill and the user. Have you got any examples getting the token? Regards – ssanga Dec 23 '18 at 21:39