how to fill a slot in alexa backend using python ask sdk

159 Views Asked by At

I need to fill the slot value of intent depending on some conditions. I referred to the following documentation. https://developer.amazon.com/en-US/docs/alexa/custom-skills/delegate-dialog-to-alexa.html#node_delegate_default_values_example

In this document, they do something like this.

    // fromCity.value is empty if the user has not filled the slot. In this example, 
    // getUserDefaultCity() retrieves the user's default city from persistent storage.
    if (!fromCity.value) {
      currentIntent.slots.fromCity.value = getUserDefaultCity();
    }

Similarly, I want to know to do this using the python ASK SDK. also how to return something similar to this?

// Return the Dialog.Delegate directive
return handlerInput.responseBuilder
  .addDelegateDirective(currentIntent)
  .getResponse();

thanks in advance!!

1

There are 1 best solutions below

0
On BEST ANSWER

I finally found the solution for this.

from ask_sdk_model.dialog import delegate_directive
updateIntent = {
    'name' : intent_name,
    'confirmation_status' : 'NONE',
    'slots' : handler_input.request_envelope.request.intent.slots
}
return handler_input.response_builder.add_directive(delegate_directive.DelegateDirective(updated_intent = updateIntent)).response