如何在 Alexa 中以编程方式清除自定义插槽值?

How to clear custom slot value programmatically in Alexa?

我有一项 Alexa 技能,需要以编程方式覆盖用户提供的值。

我试过使该值无效,然后将其作为 "updated Intent" 传递。

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

但是,输入 JSON 显示以前的值。有解决办法吗?

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

如果您有自定义插槽类型的插槽,您还必须

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

对于 V2 版本,您应该以这种方式更新意图(据我所知)

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

newIntent 应该是一个对象,您可以在其中设置新的插槽值,例如:


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

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

}