예제 #1
0
 def test_parse_response(self, m):
     """ Dialogue().parse() should parse request to api. """
     dummy_response(m)
     c = Client(apikey='')
     c.send(utt=u'ぬるぽ', apiname='Dialogue')
     ret = c.apis['Dialogue'].parse(c.last_response)
     self.assertTrue(isinstance(ret, dict))
예제 #2
0
 def test_context(self, m):
     """ Dialogue().parse() should extract context. """
     dummy_response(m)
     c = Client(apikey='')
     c.send(utt=u'ぬるぽ', apiname='Dialogue')
     ret = c.apis['Dialogue'].parse(c.last_response)
     self.assertEqual(ret['context'], 'D0yHgwljc_mhTPIGs--toQ')
예제 #3
0
 def test_context(self, m):
     """ Dialogue().parse() should extract context. """
     dummy_response(m)
     c = Client(apikey='')
     c.send(utt=u'ぬるぽ', apiname='Dialogue')
     ret = c.apis['Dialogue'].parse(c.last_response)
     self.assertEqual(ret['context'], 'D0yHgwljc_mhTPIGs--toQ')
예제 #4
0
 def test_parse_response(self, m):
     """ Dialogue().parse() should parse request to api. """
     dummy_response(m)
     c = Client(apikey='')
     c.send(utt=u'ぬるぽ', apiname='Dialogue')
     ret = c.apis['Dialogue'].parse(c.last_response)
     self.assertTrue(isinstance(ret, dict))
예제 #5
0
def main():
    args = parse_option()
    apikey = args.apikey
    if apikey is None:
        apikey = os.environ['DOCO_API_KEY']

    if apikey is None:
        sys.exit(1)

    level = logging.INFO if args.verbose is True else logging.ERROR
    logging.basicConfig(level=level, format=DocoInterface.debug_log_format)

    shiritori = args.shiritori
    options = {}
    if shiritori is True:
        options['mode'] = 'srtr'
    if args.type is not None:
        options['t'] = args.type

    client = Client(apikey=apikey, user=options)
    if args.intaractive is False:
        if args.utt is None:
            sys.exit(1)
        res = client.send(utt=args.utt, apiname='Dialogue')
        write(str(res))
    else:
        console = Console()
        console.client = client
        sys.ps1 = '>>> '
        console.interact('Welcome to docomo dialogue cli.\n^D to exit.')
def docomo_response(text):
    docomo_client = Client(apikey=os.environ['DOCOMO_API_KEY'])
    response = docomo_client.send(utt=text, apiname='Dialogue')

    logger.debug(response)

    return [{"type": "text", "text": response['utt']}]
예제 #7
0
def main():
    args = parse_option()
    apikey = args.apikey
    if apikey is None:
        apikey = os.environ['DOCO_API_KEY']

    if apikey is None:
        sys.exit(1)

    level = logging.INFO if args.verbose is True else logging.ERROR
    logging.basicConfig(level=level, format=DocoInterface.debug_log_format)

    shiritori = args.shiritori
    options = {}
    if shiritori is True:
        options['mode'] = 'srtr'
    if args.type is not None:
        options['t'] = args.type

    client = Client(apikey=apikey, user=options)
    if args.intaractive is False:
        if args.utt is None:
            sys.exit(1)
        res = client.send(utt=args.utt, apiname='Dialogue')
        write(str(res))
    else:
        console = Console()
        console.client = client
        sys.ps1 = '>>> '
        console.interact('Welcome to docomo dialogue cli.\n^D to exit.')
예제 #8
0
 def replay_chat(self, word):
     """
     チャットを返す
     :param word:
     :return:
     """
     c = Client(apikey=docomo_key)
     res = c.send(utt=word, apiname='Dialogue')
     return res['utt']
예제 #9
0
class DocomoDialogAPI(object):

    def __init__(self, api_key=None):
        api_key = os.environ.get('DOCOMO_DIALOGUE_API_KEY', api_key)
        self.__client = Client(apikey=api_key)

    def reply(self, text):
        response = self.__client.send(utt=text, apiname='Dialogue')
        utt = response['utt']

        return utt
예제 #10
0
 def test_last_response(self, m):
     """ Client().send() should send request to api and set response. """
     dummy_response(m)
     c = Client(apikey='')
     c.send(utt=u'ぬるぽ', apiname='Dialogue')
     self.assertEqual(c.last_response.status_code, 200)
예제 #11
0
 def test_send(self, m):
     """ Client().send() should send request to api. """
     dummy_response(m)
     c = Client(apikey='')
     ret = c.send(utt=u'ぬるぽ', apiname='Dialogue')
     self.assertEqual(ret['context'], 'D0yHgwljc_mhTPIGs--toQ')
예제 #12
0
 def test_last_response(self, m):
     """ Client().send() should send request to api and set response. """
     dummy_response(m)
     c = Client(apikey='')
     c.send(utt=u'ぬるぽ', apiname='Dialogue')
     self.assertEqual(c.last_response.status_code, 200)
예제 #13
0
 def test_send(self, m):
     """ Client().send() should send request to api. """
     dummy_response(m)
     c = Client(apikey='')
     ret = c.send(utt=u'ぬるぽ', apiname='Dialogue')
     self.assertEqual(ret['context'], 'D0yHgwljc_mhTPIGs--toQ')