Skip to main content

Hooks

Stentor API Reference


Stentor API Reference / stentor-models/src / Hooks

Interface: Hooks

Defined in: packages/stentor-models/src/Runtime/Hooks.ts:12

Hooks are used to provide the opportunity to modify or log runtime data at different points in the lifecycle.

Methods​

preExecution()?​

optional preExecution(event, context, callback): Promise\<{ event: object; context: RuntimeContext; callback: RuntimeCallback; }>

Defined in: packages/stentor-models/src/Runtime/Hooks.ts:24

Once the channel is selected and before the request is translated, the preExecution hook is called.

This can be used for pre-execution modifications or checks. If an error is thrown, it will be caught and returned. If you return undefined, all execution will halt without throwing an error (feel free to call the callback yourself).

Parameters​

event​

object

context​

RuntimeContext

callback​

RuntimeCallback

Returns​

Promise\<{ event: object; context: RuntimeContext; callback: RuntimeCallback; }>

Promise that either returns undefined to halt execution or the parameters back.


postRequestTranslation()?​

optional postRequestTranslation(request): Promise\<Request>

Defined in: packages/stentor-models/src/Runtime/Hooks.ts:38

This hook is called directly after the request is translated for the channel.

This can be an opportunity to modify the request but the request must be returned to continue operation.

Parameters​

request​

Request

The request after it has been translated

Returns​

Promise\<Request>

Promise that passes back the request


postContextCreation()?​

optional postContextCreation(request, context): Promise\<{ request: Request; context: Context; }>

Defined in: packages/stentor-models/src/Runtime/Hooks.ts:45

This hook, if provided is called after the request is translated then immediately after the context is created. This happens immediately before the handler is deteremined.

Parameters​

request​

Request

context​

Context

Returns​

Promise\<{ request: Request; context: Context; }>


preResponseTranslation()?​

optional preResponseTranslation(request, response, storage): Promise\<{ request: Request; response: AbstractResponseBuilder; storage: Storage; }>

Defined in: packages/stentor-models/src/Runtime/Hooks.ts:55

This hook is called before the response is translated for the channel.

Last chance to tweak the platform independent response or collect some data from the request/response (transcript).

Parameters​

request​

Request

response​

AbstractResponseBuilder

storage​

Storage

Returns​

Promise\<{ request: Request; response: AbstractResponseBuilder; storage: Storage; }>