0

I am trying to get the slot value and access it later but I am not able to get the value. Can you please help me

this is the line i am stuck with. how do i get the response the from slot and save it to the variable.

textoutput = intent['slots'].['slotsname'].['value']

code:

import logging

from random import randint
from flask import Flask, render_template
from flask_ask import Ask, statement, question, session

app = Flask(__name__)
ask = Ask(app, "/")

logging.getLogger("flask_ask").setLevel(logging.DEBUG)

@ask.intent("MAYBE")

def next_round():
    textoutput = intent['slots'].['slotsname'].['value']
    textoutput1 = 'working'
    textoutput2 = 'not working'
    if textoutput ='ftw':
        schedule_msg4 = render_template('CONNECTION2', schedule4=textoutput1)

    else:
        schedule_msg4 = render_template('CONNECTION2', schedule4=textoutput2)

    return question(schedule_msg4)

if __name__ == '__main__':
    app.run(debug=True)
Nicolò Gasparini
  • 2,228
  • 2
  • 24
  • 53
venkatesh
  • 39
  • 1
  • 5

2 Answers2

0

For selecting elements in Python lists, just use listName['key'].
For nested lists use another set of brackets: listName['key1']['key2'].

So do not separate each [] with a . So your first line should be:

textoutput = intent['slots']['slotKey']['value']
Jay A. Little
  • 3,239
  • 2
  • 11
  • 32
0

If you have defined your MAYBE intent to contain a slot named answer, a request will look like this. money is the value you want to use in your code:

"request": {
  "intent": {
    "name": "MAYBE",
    "slots": {
      "answer": {
        "name": "answer",
        "value": "money"
      }
    }
  }
  ...
}

Then, you need to adjust your function definition like so:

@ask.intent("MAYBE")    
def next_round(answer):    
    textoutput = "You said: {}".format(answer)    
    return statement(textoutput) # "You said: money"

Flask-ask will take care of extracting the value from the request. Check out the documentation.

mc51
  • 1,883
  • 14
  • 28