Global

Methods

# typeOf(input) → {string}

A more precisely type checker than Javascript built-in typeof.

Parameters:
Name Type Description
input *

The input could be of any type that should be checked.

View Source lib/type-of.js, line 13

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 useInjection parameter

params object <optional>

The useInjection additional options as object

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

View Source lib/use.injection.js, line 82

InjectedFn
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>

View Source lib/use.mock.js, line 170

Type Definitions

# async CustomFn(event) → {Response|TwiMLResponse}

Your regular function that will receive all of the providers and process the Twilio handler function.

CustomFnThis

Parameters:
Name Type Description
event *

Any aditional argument sent to the Twilio handler will be available here.

View Source lib/use.injection.js, line 33

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

View Source lib/use.injection.js, line 24

# async InjectedFn(context, event, callback) → {void}

Parameters:
Name Type Description
context object

Handler context

event object

Handler event

callback function

Handler callback function

View Source lib/use.injection.js, line 7

void
object

# Providers

An object with the declared functions to be injected into your custom regular function.

View Source lib/use.injection.js, line 18