question

NiceToMytyuk avatar image
NiceToMytyuk asked

How to run a function as soon as possible?

In my Alexa Skill i set dynamic entities in 'addRequestInterceptors' as the entities must be available as soon as possible, the issue is that if the user says 'Alexa, open SKILLNAME' the entities are initialized correctly, but if the user instead says 'Alexa, ask SKILLNAME where is DYNAMICENTITY' at this point the skill fails as the DYNAMICENTITY is not yet set.

So my question is, how can i set my dynamic entities as soon as possible like when the skill is created? I've tryed the LaunchIntent but as in the case above it's avoided if the user make the question inside the invocation..

So LaunchIntent and addRequestInterceptors aren't good to do it..

Here is my code which i should run as soon as possible:


const LoadListaPuntiVendita = {    async process(handlerInput) {        const {attributesManager, requestEnvelope} = handlerInput;        const sessionAttributes = attributesManager.getSessionAttributes();        const attributes = await attributesManager.getPersistentAttributes() || {};        const piva =  attributes.hasOwnProperty('piva') ? attributes.piva : null;        sessionAttributes["piva"] = piva;        if (!piva || piva === null) {            return;        }                let negozi = sessionAttributes['negozi']        if (!negozi) {            const response = await logic.fetchNegozi(piva);            sessionAttributes['negozi'] = response;            addDynamicEntities(handlerInput.responseBuilder, 'PuntoVenditaType', response);            }        } };
dynamic entities
10 |5000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

1 Answer

Andy Whitworth avatar image
Andy Whitworth answered

The following Amazon blog entry describes the case whereby a user launches the skill with an intent which relies upon dynamic entities having been set (look for "no one-shot support")

https://developer.amazon.com/blogs/alexa/post/db4c0ed5-5a05-4037-a3a7-3fe5c29dcb65/use-dynamic-entities-to-create-personalized-voice-experiences

It's one of the limitations of using DynamicEntities unfortunately.

I would detect the condition, load the entity values and return a response setting the DynamicEntities along with a voice response which invited the user to interact again in a manner which would use the dynamic entities.

2 comments
10 |5000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

NiceToMytyuk avatar image NiceToMytyuk commented ·

so where should i set the DynamicEntities? for now i have an intent wich require the fullfill of slot DATE and the CUSTOM for dynamic entities, the issue is that if the user give in one intent DATE and CUSTOM the custom will not be accepted as Dynamic Entities are not set yet...

0 Likes 0 ·
Amazon_Bernardo Bezerra avatar image Amazon_Bernardo Bezerra ♦♦ NiceToMytyuk commented ·

Hello @NiceToMytyuk and thanks for your message.

You can find more information about Dynamic Entities over at our documentation portal.

Regards,
Barry

0 Likes 0 ·