How to clear custom slot value programmatically in Alexa?

允我心安 提交于 2020-03-23 07:53:21

问题


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?


回答1:


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;



回答2:


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();

}


来源:https://stackoverflow.com/questions/48090335/how-to-clear-custom-slot-value-programmatically-in-alexa

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!