Who's there... Me
Who's there... Me

Reputation: 56

How do I call the environmental variables from within a Twilio Function?

If you want to call a Twilio environmental variable from within a Twilio function, you can do it like this.

context.myVariableName

I didn't see the answer on Stack Exchange, I hope it helps. To set the environmental variable, it is done from "Configure" in the Functions menu.

Upvotes: 0

Views: 1112

Answers (1)

philnash
philnash

Reputation: 73027

Twilio developer evangelist here.

This is correct, though not really a question. You can find out all about how the environment for a Twilio Function is constructed in the documentation.

Notably, in the function signature exports.handler = function(context, event, callback) the following is the case:

context contains:

  • all environment variables that you set in the Configure section

and, if you have "Enable ACCOUNT_SID and AUTH_TOKEN" checked in the Configure section:

  • ACCOUNT_SID and AUTH_TOKEN set to the relevant values for your account
  • a function, getTwilioClient(), which will return an API client from the Twilio module authenticated with your account sid and auth token

event then contains:

  • query and body parameters from GET or POST requests

and callback is a function that should be invoked once you are finished processing the request and would like to complete execution. If there was an error in execution, pass that error as the first argument of callback. Otherwise, pass null as the first argument and the response you want to return as the second argument.

As I said, this is all in the documentation, but I hope it helps if you were missing something.

Upvotes: 2

Related Questions