diff --git a/README.md b/README.md index b9df0b0..94c1c87 100644 --- a/README.md +++ b/README.md @@ -85,7 +85,10 @@ npm install twilio-functions-utils ```js // File: assets/create.private.js -exports.create = async function () { +exports.create = async function (event) { + // Here you can acess Twilio Client as client and Context as props (so you can get env vars). + const { client, props } = this + return new Promise((resolve, reject) => { const random = Math.random(); @@ -122,7 +125,7 @@ const { create } = require(Runtime.getAssets()['/create.js'].path) */ async function createAction(event) { // You can perform all your "controller" level actions, as you have access to the request headers and cookies. - const { cookies, request } = this + const { cookies, request, client, props } = this // Then just call the useCase you provided to handler by using useInjection. const useCaseResult = await this.useCase.create(event) diff --git a/lib/use.injection.js b/lib/use.injection.js index e855fcb..8f0926d 100644 --- a/lib/use.injection.js +++ b/lib/use.injection.js @@ -41,9 +41,10 @@ exports.useInjection = (fn, params) => const { providers, validateToken } = params; const [context, event, callback] = args; const { getTwilioClient, ...properties } = context; + const client = getTwilioClient(); const useCaseThat = { - client: getTwilioClient, + client, props: properties, }; @@ -56,7 +57,7 @@ exports.useInjection = (fn, params) => const that = { request, cookies, - client: getTwilioClient(), + client, props: properties, useCase: providerNames.reduce((p, c) => { Reflect.defineProperty(