Skip to content

Instantly share code, notes, and snippets.

@jagrament
Last active June 23, 2018 03:00
Show Gist options
  • Save jagrament/f720459a6d0ff32956db2492679d9b6f to your computer and use it in GitHub Desktop.
Save jagrament/f720459a6d0ff32956db2492679d9b6f to your computer and use it in GitHub Desktop.
Connect Expert Agent Developer Dashboard(https://developers.sebastien.ai) to Repl-AI(https://repl-ai.jp)
import json
import urllib
def respond(err, res=None):
return {
'statusCode': '400' if err else '200',
'body': err.message if err else json.dumps(res),
'headers': {
'Content-Type': 'application/json'
}
}
def dialogue_request(headers,params):
request_url = "https://api.repl-ai.jp/v1/dialogue"
json_data = json.dumps(params).encode("utf-8")
request = urllib.request.Request(request_url, data=json_data, method="POST", headers=headers)
with urllib.request.urlopen(request) as response:
response_body = response.read().decode("utf-8")
result = json.loads(response_body)
return result
def registration_request(headers,params):
request_url = "https://api.repl-ai.jp/v1/registration"
json_data = json.dumps(params).encode("utf-8")
request = urllib.request.Request(request_url, data=json_data, method="POST", headers=headers)
with urllib.request.urlopen(request) as response:
response_body = response.read().decode("utf-8")
result = json.loads(response_body)
print(result)
def lambda_handler(event, context):
print("Received event: " + json.dumps(event, indent=2))
payload = json.loads(event['body'])
intent = payload["args"]["intent"]
if intent == "replai":
headers = {
'Content-Type': 'application/json',
'x-api-key': payload["args"]["apikey"][0]
}
registration_params = {
"botId": payload["args"]["botId"][0],
"appUserId": payload["user_id"]
}
dialogue_params = {
"appUserId": payload["user_id"],
"botId": payload["args"]["botId"][0],
"voiceText": payload["args"]["utterance"][0],
"initTopicId": payload["args"]["initTopicId"][0]
}
registration_request(headers,registration_params)
result = dialogue_request(headers,dialogue_params)
if result is not None:
return respond(None, {"error_code": "success", "status": "true", "user_id": payload["user_id"], "bot_id": payload["bot_id"], "params": {"status": "true", "message": result["systemText"]["expression"]}})
elif intent == "default":
return respond(None, {"error_code": "success", "status": "true", "user_id": payload["user_id"], "bot_id": payload["bot_id"], "params": {"status": "true", "message": "よくわかんなーい"}})
@jagrament
Copy link
Author

Setting

Please set the parameters as the default value of not requierd slots.

  • apikey
  • botId
  • initTopicId

※ Use Entity with null value, tthat are not spoken.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment