tropo / tropo-webapi-python

A set of Python classes for working with the Tropo WebAPI
MIT License
85 stars 33 forks source link

Can't sort out syntax structure for choices for ask #21

Closed JustinDupree closed 13 years ago

JustinDupree commented 13 years ago

Python library defines ask like this:

action = 'ask' options_array = ['attempts', 'bargein', 'choices', 'minConfidence', 'name', 'recognizer', 'required', 'say', 'timeout', 'voice', 'allowSignals']

def __init__(self, choices, **options):
    self._dict = {}
    if (isinstance(choices, basestring)):
        self._dict['choices'] = Choices(choices).json
    else:
        self._dict['choices'] = choices['choices']
    for opt in self.options_array:
        if opt in options:
            if ((opt == 'say') and (isinstance(options['say'], basestring))):
                self._dict['say'] = Say(options['say']).json
            else:
                self._dict[opt] = options[opt]

I can't figure out the syntax to structure "choices"

t.ask(choices = {"value":"[4-5 DIGITS]", "mode":"dtmf", "terminator":"#"}, timeout=15, name="digit", say = "What's your four or five digit pin? Press pound when finished.")

it gives me this exception:

<type 'exceptions.KeyError'> occurred on '/index.json': 'choices' Traceback: Traceback (most recent call last): File "/Library/Python/2.6/site-packages/itty.py", line 271, in handle_request response = callback(request, _kwargs) File "/Library/Python/2.6/site-packages/itty.py", line 412, in new return method(_args, _kwargs) File "webapi_rework.py", line 9, in index t.ask(choices = {"value":"[4-5 DIGITS]", "mode":"dtmf", "terminator":"#"}, timeout=15, name="digit", say = "What's your four or five digit pin? Press pound when finished.") File "/Users/justindupree/Python WebAPI/tropo-webapi-python/tropo.py", line 525, in ask self._steps.append(Ask(choices, *_options).obj) File "/Users/justindupree/Python WebAPI/tropo-webapi-python/tropo.py", line 94, in init self._dict['choices'] = choices['choices'] KeyError: 'choices'

JustinDupree commented 13 years ago

This is closed, but I still don't know the answer?

egilchri commented 13 years ago

Hi Justin,

I made some changes to tropo.py to address this issue, and provided a sample at https://github.com/tropo/tropo-webapi-python/blob/master/samples/gh-21.choices.py .

Sorry you didn't see it. Please let me know if you have questions.

Ted

On Mon, May 23, 2011 at 12:04 PM, JustinDupree < reply@reply.github.com>wrote:

This is closed, but I still don't know the answer?

Reply to this email directly or view it on GitHub: https://github.com/tropo/tropo-webapi-python/issues/21#comment_1222434

"Speech, not just for humans"

http://www.google.com/profiles/egilchri about.me/ted.gilchrist

JustinDupree commented 13 years ago

Confirmed this works as expected, all good now.