In the past, I installed two separate AWB iamba written in Java. One for use with Alexa and one for use with Api.ai. They simply return "Hello world" to each helper api. Therefore, although they are simple, they work. As I started writing more and more code for each of them, I began to see how similar my Java code was, and I just repeated myself with two separate lambdas.
Fast Forward
Now I am working with a single AWS lambda that can handle input from both Alexa and Api.ai, but I have problems. Currently, I think that when starting lambda there will be a simple if statement:
The following code is not real, just what I can do in my head
if (figureOutIfInputType.equals("alexa")){ runAlexaCode(); } else if (figureOutIfInputType.equals("api.ai")){ runApiAiCode(); }
Now I need to somehow say whether the function is called alexey or api.ai.
This is my actual java right now:
public class App implements RequestHandler<Object, String> { @Override public String handleRequest(Object input, Context context) { System.out.println("myLog: " + input.toString()); return "Hello from AWS"; }
Then I launched a lambda from Alexa and Api.ai to find out which object will be created in java.
API.ai
{id=asdf-6801-4a9b-a7cd-asdffdsa, timestamp=2017-07- 28T02:21:15.337Z, lang=en, result={source=agent, resolvedQuery=hi how are you, action=, actionIncomplete=false, parameters={}, contexts=[], metadata={intentId=asdf-3a2a-49b6-8a45-97e97243b1d7, webhookUsed=true, webhookForSlotFillingUsed=false, webhookResponseTime=182, intentName=myIntent}, fulfillment= {messages=[{type=0, speech=I have failed}]}, score=1}, status= {code=200, errorType=success}, sessionId=asdf-a7ac-43c8-8ae8- bc1bf5ecaad0}
Alexa
{version=1.0, session={new=true, sessionId=amzn1.echo-api.session.asdf- 7e03-4c35-9d98-d416eefc5b23, application= {applicationId=amzn1.ask.skill.asdf-a02e-4938-a747-109ea09539aa}, user= {userId=amzn1.ask.account.asdf}}, context={AudioPlayer= {playerActivity=IDLE}, System={application= {applicationId=amzn1.ask.skill.07c854eb-a02e-4938-a747-109ea09539aa}, user={userId=amzn1.ask.account.asdf}, device= {deviceId=amzn1.ask.device.asdf, supportedInterfaces={AudioPlayer={}}}, apiEndpoint=https:
So now I have both exits Alexa and Api.ai, and they are different. So good. I can tell which one. but i'm stuck. I'm not sure if I should try to create an AlexaInput object and an ApiAIinput object.
Am I doing all this wrong? Am I mistaken when trying to get one lambda to fulfill my βhelpersβ requests from several services (Alexa and ApiAI)?
Any help would be greatly appreciated. Of course, someone else needs to write their helpers in AWS and wants to reuse their code for both of the "helpers" platforms.