コード例 #1
0
class AlexaBot(object):
    ''' Simple class which moves the Flask Ask decorators to simple config
    '''
    def __init__(self, config):
        # set up the Flask app
        self.app = Flask(__name__)
        self.ask = Ask(self.app, '/')

        # load config
        # the config is a list of lists (keeping w/ what the students know from Eliza):
        # 0: intent name
        # 1: intent method to call
        for intent_config in config:
            intent_name = intent_config[0]
            func = intent_config[1]

            if intent_name == 'launch':
                # special case the 'launch' method
                func = self.ask.launch(func)
            elif intent_name.lower().startswith('on_playback'):
                # special case 'on_playback'
                # get the method name from the string
                method = getattr(self.ask, intent_name)
                func = method(func)
            else:
                func = self.ask.intent(intent_name)(func)

    def start(self, debug=False):
        ''' start it up
            Note: debug=True does not play well with jupyter notebook
        '''
        # start it up
        self.app.run(debug=debug)
コード例 #2
0
ファイル: app.py プロジェクト: willzhang05/cryptoticker
    return statement(speech)


ask.intent('AMAZON.CancelIntent')(end)
ask.intent('AMAZON.StopIntent')(end)


@ask.intent('AMAZON.HelpIntent')
def help():
    help_message = 'You can say tell me the price of a cryptocurrency, for example, bitcoin or ethereum. You can also say exit... What can I help you with?'
    help_reprompt = 'Sorry, I didn\'t get that. What would you like me to do?'
    logger.info('question = {}, {}'.format(help_message, help_reprompt))
    return question(help_message).reprompt(help_reprompt)


ask.launch(help)


@ask.intent('GetPriceIntent', default={'coin': 'NULL'})
def get_price(coin):
    print(request)
    if coin == 'NULL':
        error_message = 'Sorry, I didn\'t get that. Please specify a cryptocurrency... What can I help you with?'
        error_reprompt = 'What would you like me to do?'
        logger.info('question = {}, {}'.format(error_message, error_reprompt))
        return question(error_message).reprompt(error_reprompt)

    r = requests.get(ENDPOINT + coin)
    if r.status_code == 200:
        out = r.json()[0]
        speech = 'The market price of {} is currently {} US Dollars'.format(