Can Alexa Smart Home Discovery be triggered programmatically? - alexa

Is it possible to programmatically trigger an Alexa smart home “discovery”?
I’m working on a custom skill that can be used to add and configure devices in an associated smart home skill. Using the custom skill, the user can add and edit device names recognized by the smart home skill.
This works fine, but as expected requires the user to perform "discover new devices" before the smart home skill will pick up the changes.
Is there a way that the custom skill could trigger a new discovery on the smart home skill to pick up the new device info?
I'd rather not have the custom skill tell the user “Ok, now go open the Alexa app, go to smart home, and select discovery".

There is a workaround for your problem. If you see how Alexa.Discovery works you have to make a request to the endpoint. If you have the access to the endpoint you can send the request and get the new devices int the response from the endpoint.
Discovery Request :
{
"directive": {
"header": {
"namespace": "Alexa.Discovery",
"name": "Discover",
"payloadVersion": "3",
"messageId": "1bd5d003-31b9-476f-ad03-71d471922820"
},
"payload": {
"scope": {
"type": "BearerToken",
"token": "access-token-from-skill"
}
}
}
}

Related

Pull data fro API using Azure Logic Apps

I need to Pull data from a 3rd party API and minor process that data and then send it to DB. Is there any connector to pull API data using Logic App? Any connector or Action? How to start.
It seems you wants to fetch data from any API using logic App right?
Yes you can do it using Logic Apps Custom Connector on azure portal see the screen shot below:
How to connect any API with Custom Connector:
Step 1: Create New Custom Connector
To create a Custom Connector go to azure portal and in All services search for Logic Apps Custom Connector click on it and Add New Connector. see the screen shot:
Step 2: Edit Custom Connector
Once you have created new custom connector then to add your API with it you have to Edit it to configure your API request and response with the new custom connector
Step 3: Configure Custom Connector
There are 3 part of custom Connector
1. General
Here you would see Host enter your API main domain name like dotnetavalanche.azurewebsites.net
Leave base URL blank
2. Security
For test propose no authentication required just leave it blank
3. Definition
enter a Summary note , description but surely enter a Operation ID which should unique like TestAPI
Request
Then in Request selection click on Import from sample and enter your API method type Like POST or GET
Full URL of your API for example: https://dotnetavalanche.azurewebsites.net/api/PartnerBotRequest
See the screen shot:
Response:
Here click on Add default response and add Json of your expected response from API
Call Your custom Connector On Azure Logic App
Go to azure logic App and click on Http Request on Request Body JSON Schema paste below JSON
{
"type": "object",
"properties": {
"title": {
"type": "string"
},
"description": {
"type": "string"
},
"email": {
"type": "string"
}
}
}
Then click on Next Step and add your custom connector like below:
Then finally add new Step as Response
Configure the response as below screen shot:
If you still have any query feel free to share. Thanks and happy coding!

Alexa, get skill from LaunchRequest Intent

I got 3 skills in my account, eg SkillA, SkillB and SkillC.
I am using an endpoint url to listen to these skills, and my server is common for all the 3 skills. So if I try to invoke a skill by saying open SkillA it invokes LaunchRequest. Same is the case with other 2 skills.
So how would I be able to know which Skill's LaunchRequest was invoked.
My server is ruby with Ralyxa Gem.
For every skill there is a unique Skill ID known as applicationId. Making use of this applicationId from the request JSON you can easily determine from which skill the request came in.
You can find this applicationId under application object in every request from Alexa to your backend.
{
"version": "1.0",
"session": {
"new": true,
"sessionId": "amzn1.echo-api.session.xxxx-xxxx-xxxx-xxxx-xxxxxxx",
"application": {
"applicationId": "amzn1.ask.skill.xxxx-xxxx-xxxx-xxxx-xxxx"
},
"user": {
"userId": "amzn1.ask.account.xxxxxxxxxxxxxx"
}
},
...
You can also view the Skill ID from Alexa developers console where your Alexa Skills are listed.

Logic apps ARM deployment fails for API connections using OAuth that already exist and are connected

Recently I'm gettings errors when deploying logic apps using ARM templates. I get the errors for certain API connections that are used by the logic apps. The error I receive is:
Input parameters are invalid. See details for more information. Details:errorCode: ParameterNotDefined. Message: Parameter '$connectionCreator' is not allowed on the connection since it was not defined as a connection parameter when the API was registered.
I only get these errors for existing and authenticated connections of type dynamicscrmonline and azureeventgrid. As long as the connection doesn't exist or isn't yet authenticated, the deployment succeeds. It appears to be happening only with API connections that use OAuth. This used to work in the past and I'm not sure what changed.
This is an example of a connection that gives me the error:
{
"type": "MICROSOFT.WEB/CONNECTIONS",
"apiVersion": "2016-06-01",
"name": "[parameters('dynamicscrmonline_1_Connection_Name')]",
"location": "westeurope",
"properties": {
"api": {
"id": "[concat(subscription().id, '/providers/Microsoft.Web/locations/', 'westeurope', '/managedApis/', 'dynamicscrmonline')]"
},
"displayName": "[parameters('dynamicscrmonline_1_Connection_DisplayName')]"
}
},
I had the same error with Azure AD API and send grid.
Try to delete the existing connections API associated to your existing Logic App and then redeploy.
It works for me.

Access control in LoopBack

I am building an events management web app for my clients based on StrongLoop API platform whereby I need to limit CRUD access to data to the currently logged in user (a client).
I have followed these tutorials https://github.com/strongloop/loopback-faq-user-management, https://github.com/strongloop/loopback-example-access-control to successfully login and logout, and now need to implement bringing back the correct data on the AngularJS client.
I have setup a relation on my 'events' model as follows:
"relations": {
"user": {
"type": "belongsTo",
"model": "User",
"foreignKey": "ownerId"
}
}
and also on the built-in User model:
"relations": {
"events": {
"type": "hasMany",
"model": "event",
"foreignKey": "ownerId"
}
}
Not sure where/how to define the access token after login to make API calls. Do I also need to apply a filter on $scope.events = Event.find(); to retrieve only the records where ownerID: <currentUserId> or should the ACLs achieve that for me?
Any help much appreciated.
1) Access token automatically saved to localStorage/sessionStorage and to angular-sdk internals. So it attached to authorization header on every request to API.
2) Yes, you should apply filter, because ACL just allow or deny access to remote methods. By the way, another way to query user's events is
User.events({id: currentUserId})

How does a service identify the user?

Use case:
A user takes a beautiful photo and wants to save it to their evernote account.
User authorizes with OAuth 2.0. The service stores their credentials.
Just after the OAuth 2.0 dance completes, the service inserts a contact called "Save to Evernote".
Next, the service subscribes to updates in this user's timeline by inserting a subscription for the timeline collection.
The user activates the contact. Save to Evernote is now fully set up.
Over time, the user takes photos.
The user shares a photo with Save to Evernote. This makes the timeline card associated with this photo accessible to the service.
Because the service is subscribed to timeline updates, a notification is sent to your service. This notification links to the timeline item containing the shared photo.
The service examines the notification and uses the included id to fetch the timeline card that contains the photo.
Next, the service examines the timeline item and uses the attachment ID to fetch the bytes of the photo.
The service uploads the photo to the user's Evernote.
Finally, the service constructs a new timeline card and inserts it into the user's timeline card with the success message.
From the Mirror API Documentation it appears that once a user shares a timeline item the service receives a POST quite like this:
{
"collection": "timeline",
"itemId": "3hidvm0xez6r8_dacdb3103b8b604_h8rpllg",
"operation": "UPDATE",
"userToken": "harold_penguin",
"verifyToken": "random_hash_to_verify_referer",
"userActions": [
{
"type": "SHARE"
}
]
}
Is the userToken a value that I receive when first authenticating the application? If so can I use that value to connect the POST received from Glass with the User saved in my database? If not how do I connect the share to my service's contact with the Glass user so that my service can perform services specific to that user on their behalf?
The userToken is indeed the field you use to correlate the notification back to the user who triggered it.
You set the userToken when you create a subscription for that user. Whatever value you specify when you insert the subscription is provided as the userToken for all of the notifications that it yields. This means that when you create subscriptions, you always want to use unique identifiers that your system can correlate back to the correct user.
For example:
Jane authenticates with your service. Jane has the unique user ID of 42 in your Glassware's database.
At the time of authentication, you subscribe to her timeline collection by inserting this subscription:
{
"collection": "timeline"
"userToken": "42",
"callbackUrl": "https://example.com/notify/callback"
}
Jane shares a photo with your Glassware.
A notification is sent to your service. It looks something like this:
{
"collection": "timeline",
"itemId": "3hidvm0xez6r8_dacdb3103b8b604_h8rpllg",
"operation": "UPDATE",
"userToken": "42",
"userActions": [
{
"type": "SHARE"
}
]
}
Your Glassware uses the userToken property to look up the correct user: Jane.
The rest of the story proceeds as you describe in your question.

Resources