Advertisement
aa_frey

api.ai slack

Mar 26th, 2016
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.57 KB | None | 0 0
  1. @respond_to('(.*)', re.IGNORECASE)
  2. def survey_reply(message, something):
  3.     ai = apiai.ApiAI(CLIENT_ACCESS_TOKEN, SUBSCRIPTION_KEY)
  4.     request = ai.text_request()
  5.     request.query = something
  6.     response = request.getresponse()
  7.     data = json.loads(response.read()) #convert string to dict
  8.  
  9.     user = message.body['user']
  10.     print data.__class__
  11.     print user
  12.     if len(data['result']['fulfillment']['speech']) > 0:
  13.         message.reply(data['result']['fulfillment']['speech'])
  14.     else:
  15.         message.reply(data['result']['metadata']['html'])
  16.     print data
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement