Methods
# typeOf(input) → {string}
A more precisely type checker than Javascript built-in typeof.
Parameters:
Name | Type | Description |
---|---|---|
input |
*
|
The |
Returns a string with the input
type.
string
Example
typeOf(['myName', 'checker']); // "Array"
typeOf('myName'); // "String"
# useInjection(fn, paramsopt) → {InjectedFn}
The useInjection method takes two parameters. The first to apply as a handler and the last is an object of configuration options. It reduces the need to apply frequent try-catches and improving context management, making it no longer necessary to return the callback() method in all functions.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
fn |
CustomFn
|
Your custom function must be defined here as the first |
|
params |
object
|
<optional> |
The |
providers |
Providers
|
<optional> |
The providers that should be injected into your CustomFn |
validateToken |
boolean
|
<optional> |
A boolean to request for Token validation from Twilio Flex |
Example
const { useInjection, Response } = require('twilio-functions-utils');
const { create } = require(Runtime.getFunctions()['create'].path)
async function createAction(event) {
const { cookies, request, env } = this
const providerResult = await this.providers.create(event)
if (providerResult.isError) {
return new BadRequestError(providerResult.error);
}
return new Response(providerResult.data, 201);
}
exports.handler = useInjection(createAction, {
providers: {
create,
},
validateToken: true
});
# useMock(fn, paramsopt)
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
fn |
function
|
||
params |
object
|
<optional> |
|
providers |
object
|
<optional> |
|
env |
object
|
<optional> |
|
client |
object
|
<optional> |
Type Definitions
# async CustomFn(event) → {Response|TwiMLResponse}
Your regular function that will receive all of the providers and process the Twilio handler function.
Parameters:
Name | Type | Description |
---|---|---|
event |
*
|
Any aditional argument sent to the Twilio handler will be available here. |
object
# CustomFnThis
Properties:
Name | Type | Description |
---|---|---|
request |
object
|
The request values as headers |
cookies |
object
|
The request cookies |
env |
object
|
All of the ENV vars available through context can be founded here |
providers |
Providers
|
The providers attached on useInjection options will be available here |
# async InjectedFn(context, event, callback) → {void}
Parameters:
Name | Type | Description |
---|---|---|
context |
object
|
Handler context |
event |
object
|
Handler event |
callback |
function
|
Handler callback function |
void
object
# Providers
An object with the declared functions to be injected into your custom regular function.