简体   繁体   中英

How to clear custom slot value programmatically in Alexa?

I have an Alexa skill which requires to programmatically override the values given by the user.

I have tried nullifying the value and later pass it in as the "updated Intent".

this.event.request.intent.userPrompt.value = null;
var updatedIntent = this.event.request.intent;
this.emit(':elicitSlot', 'userPrompt',"Say something","Say something", updatedIntent);

However, the input JSON shows previous value. Is there a solution to this?

there is

delete this.event.request.intent.slots.<slotname>.value;
var updatedIntent = this event.request.intent;
this.emit(':elicitSlot', <slotname>,"Say something","Say something", updatedIntent);

if you have a slot with a custom slot type you also have to

delete this.event.request.intent.slots.<slotname>.resolutions;

For the version V2 you should update the intent in this way (as far as I know)

 handlerInput.responseBuilder
    .addDelegateDirective(newIntent)
    .getResponse();

newIntent should be an object where you can set your new slot values, for example :


const resetIntent = (handlerInput) => {
  const intent = {
    name : 'myIntentName',
    confirmationStatus: 'NONE',
    slots : {
      slotOne: {
        name: 'slotOne',
        confirmationStatus: 'NONE'
      }
    }
  }

  return handlerInput.responseBuilder
    .addDelegateDirective(intent)
    .getResponse();

}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM