Package io.micronaut.chatbots.lambda
Class AbstractHandler<B extends BotConfiguration,I,O>
java.lang.Object
io.micronaut.function.executor.AbstractExecutor<C>
io.micronaut.function.executor.AbstractFunctionExecutor<I,O,com.amazonaws.services.lambda.runtime.Context>
io.micronaut.function.aws.MicronautRequestHandler<com.amazonaws.services.lambda.runtime.events.APIGatewayProxyRequestEvent,com.amazonaws.services.lambda.runtime.events.APIGatewayProxyResponseEvent>
io.micronaut.chatbots.lambda.AbstractHandler<B,I,O>
- Type Parameters:
B- The Bot configurationI- input type.O- output type.
- All Implemented Interfaces:
com.amazonaws.services.lambda.runtime.RequestHandler<com.amazonaws.services.lambda.runtime.events.APIGatewayProxyRequestEvent,,com.amazonaws.services.lambda.runtime.events.APIGatewayProxyResponseEvent> io.micronaut.context.ApplicationContextProvider,io.micronaut.function.aws.MicronautLambdaContext,io.micronaut.function.executor.FunctionExecutor<com.amazonaws.services.lambda.runtime.events.APIGatewayProxyRequestEvent,,com.amazonaws.services.lambda.runtime.events.APIGatewayProxyResponseEvent> Closeable,AutoCloseable
public abstract class AbstractHandler<B extends BotConfiguration,I,O>
extends io.micronaut.function.aws.MicronautRequestHandler<com.amazonaws.services.lambda.runtime.events.APIGatewayProxyRequestEvent,com.amazonaws.services.lambda.runtime.events.APIGatewayProxyResponseEvent>
Abstract class to handle a Chatbots webhook in an AWS Lambda Handler.
- Since:
- 1.0.0
- Author:
- Sergio del Amo
-
Field Summary
Fields inherited from class io.micronaut.function.aws.MicronautRequestHandler
ENV_X_AMZN_TRACE_ID, LAMBDA_TRACE_HEADER_PROPFields inherited from class io.micronaut.function.executor.AbstractExecutor
applicationContextFields inherited from interface io.micronaut.function.aws.MicronautLambdaContext
ENVIRONMENT_LAMBDA -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedDefault constructor; will initialize a suitable ApplicationContext for Lambda deployment.protectedAbstractHandler(io.micronaut.context.ApplicationContext applicationContext) Constructor used to inject a preexistingApplicationContext.protectedAbstractHandler(io.micronaut.context.ApplicationContextBuilder applicationContextBuilder) Constructor used to inject a preexistingApplicationContextBuilder. -
Method Summary
Modifier and TypeMethodDescriptioncom.amazonaws.services.lambda.runtime.events.APIGatewayProxyResponseEventexecute(com.amazonaws.services.lambda.runtime.events.APIGatewayProxyRequestEvent request) protected abstract @NonNull Dispatcher<B,I, O> protected abstract @NonNull io.micronaut.serde.ObjectMapperprotected @NonNull com.amazonaws.services.lambda.runtime.events.APIGatewayProxyResponseEventok()protected @NonNull com.amazonaws.services.lambda.runtime.events.APIGatewayProxyResponseEventprotected @NonNull com.amazonaws.services.lambda.runtime.events.APIGatewayProxyResponseEventprotected @NonNull com.amazonaws.services.lambda.runtime.events.APIGatewayProxyResponseEventprotected abstract @NonNull com.amazonaws.services.lambda.runtime.events.APIGatewayProxyResponseEventokSerializer(@NonNull Object body) parseBot(@NonNull com.amazonaws.services.lambda.runtime.events.APIGatewayProxyRequestEvent request) parseHeader(@NonNull com.amazonaws.services.lambda.runtime.events.APIGatewayProxyRequestEvent request, @NonNull String headerName) protected com.amazonaws.services.lambda.runtime.events.APIGatewayProxyResponseEventresponse(io.micronaut.http.HttpStatus httpStatus) protected @NonNull com.amazonaws.services.lambda.runtime.events.APIGatewayProxyResponseEventprotected @NonNull com.amazonaws.services.lambda.runtime.events.APIGatewayProxyResponseEventprotected abstract @io.micronaut.core.annotation.NonNull booleanvalidate(@NonNull com.amazonaws.services.lambda.runtime.events.APIGatewayProxyRequestEvent request) Methods inherited from class io.micronaut.function.aws.MicronautRequestHandler
buildApplicationContext, convertInput, handleRequest, newApplicationContextBuilderMethods inherited from class io.micronaut.function.executor.AbstractExecutor
close, getApplicationContext, resolveFunction, resolveFunctionName, startEnvironment
-
Constructor Details
-
AbstractHandler
protected AbstractHandler()Default constructor; will initialize a suitable ApplicationContext for Lambda deployment. -
AbstractHandler
protected AbstractHandler(io.micronaut.context.ApplicationContext applicationContext) Constructor used to inject a preexistingApplicationContext.- Parameters:
applicationContext- the application context
-
AbstractHandler
protected AbstractHandler(io.micronaut.context.ApplicationContextBuilder applicationContextBuilder) Constructor used to inject a preexistingApplicationContextBuilder.- Parameters:
applicationContextBuilder- the application context builder
-
-
Method Details
-
execute
public com.amazonaws.services.lambda.runtime.events.APIGatewayProxyResponseEvent execute(com.amazonaws.services.lambda.runtime.events.APIGatewayProxyRequestEvent request) -
validate
@NonNull protected abstract @io.micronaut.core.annotation.NonNull boolean validate(@NonNull @NonNull com.amazonaws.services.lambda.runtime.events.APIGatewayProxyRequestEvent request) - Parameters:
request- API Gateway Request- Returns:
- Whether the request is valid or not
-
parseBot
@NonNull protected abstract @NonNull Optional<B> parseBot(@NonNull @NonNull com.amazonaws.services.lambda.runtime.events.APIGatewayProxyRequestEvent request) - Parameters:
request- API Gateway Request- Returns:
- The Bot associated to the request
-
getObjectMapper
@NonNull protected abstract @NonNull io.micronaut.serde.ObjectMapper getObjectMapper()- Returns:
- The Object Mapper
-
getDispatcher
- Returns:
- The Dispatcher
-
ok
@NonNull protected @NonNull com.amazonaws.services.lambda.runtime.events.APIGatewayProxyResponseEvent ok()- Returns:
- Returns a 200 response
-
unauthorized
@NonNull protected @NonNull com.amazonaws.services.lambda.runtime.events.APIGatewayProxyResponseEvent unauthorized()- Returns:
- Returns a 401 response
-
serverError
@NonNull protected @NonNull com.amazonaws.services.lambda.runtime.events.APIGatewayProxyResponseEvent serverError()- Returns:
- Returns a 500 response
-
response
protected com.amazonaws.services.lambda.runtime.events.APIGatewayProxyResponseEvent response(io.micronaut.http.HttpStatus httpStatus) - Parameters:
httpStatus- HTTP Status- Returns:
- Returns a 500 response
-
okSerializer
@NonNull protected abstract @NonNull com.amazonaws.services.lambda.runtime.events.APIGatewayProxyResponseEvent okSerializer(@NonNull @NonNull Object body) -
okJson
@NonNull protected @NonNull com.amazonaws.services.lambda.runtime.events.APIGatewayProxyResponseEvent okJson(@NonNull @NonNull Object body) - Parameters:
body- The Body to be serialized as JSoN- Returns:
- Returns a 200 response
-
okHtml
@NonNull protected @NonNull com.amazonaws.services.lambda.runtime.events.APIGatewayProxyResponseEvent okHtml(@NonNull @NonNull Object body) - Parameters:
body- The Body as an HTML String- Returns:
- Returns a 200 response with HTML content type
-
ok
@NonNull protected @NonNull com.amazonaws.services.lambda.runtime.events.APIGatewayProxyResponseEvent ok(@NonNull @NonNull Object body, @NonNull @NonNull String contentType) - Parameters:
body- The Body to respondcontentType- Content Type of the resonse- Returns:
- Returns a 200 response with the supplied content type and body
-
parseHeader
@NonNull protected @NonNull Optional<String> parseHeader(@NonNull @NonNull com.amazonaws.services.lambda.runtime.events.APIGatewayProxyRequestEvent request, @NonNull @NonNull String headerName) - Parameters:
request- The API Gateway RequestheaderName- HTTP Header Name- Returns:
- The HTTP Header Value
-