Options
All
  • Public
  • Public/Protected
  • All
Menu

A set of utilities for accessing and modifying environment variables in Twilio Functions.

Index

Functions

getCurrentEnvironment

  • getCurrentEnvironment(context: { DOMAIN_NAME: string; ENVIRONMENT_SID: undefined | string; PATH: string; SERVICE_SID: undefined | string; getTwilioClient: any }): Promise<EnvironmentInstance | undefined>
  • Given a Serverless Context object, finds and returns the first available EnvironmentInstance.

    Note that if running on localhost, or if no EnvironmentInstances are available, this function returns undefined.

    Usage: const environment = await getCurrentEnvironment(context);

    Parameters

    • context: { DOMAIN_NAME: string; ENVIRONMENT_SID: undefined | string; PATH: string; SERVICE_SID: undefined | string; getTwilioClient: any }

      The current Serverless context.

      • DOMAIN_NAME: string
      • ENVIRONMENT_SID: undefined | string
      • PATH: string
      • SERVICE_SID: undefined | string
      • getTwilioClient:function
        • getTwilioClient(options?: TwilioClientOptions): Twilio
        • Parameters

          • Optional options: TwilioClientOptions

          Returns Twilio

    Returns Promise<EnvironmentInstance | undefined>

    The first valid environment for the given context, or undefined.

getEnvironmentVariable

  • getEnvironmentVariable(context: { DOMAIN_NAME: string; ENVIRONMENT_SID: undefined | string; PATH: string; SERVICE_SID: undefined | string; getTwilioClient: any }, environment: EnvironmentInstance, key: string): Promise<VariableInstance | undefined>
  • Given a Serverless Context, an EnvironmentInstance (usually from getCurrentEnvironment), and a string key, returns the environment variable corresponding to key, or undefined if no matching variable exists.

    Usage: const var = await getEnvironmentVariable(context, environment, 'var');

    Parameters

    • context: { DOMAIN_NAME: string; ENVIRONMENT_SID: undefined | string; PATH: string; SERVICE_SID: undefined | string; getTwilioClient: any }

      The current Serverless context.

      • DOMAIN_NAME: string
      • ENVIRONMENT_SID: undefined | string
      • PATH: string
      • SERVICE_SID: undefined | string
      • getTwilioClient:function
        • getTwilioClient(options?: TwilioClientOptions): Twilio
        • Parameters

          • Optional options: TwilioClientOptions

          Returns Twilio

    • environment: EnvironmentInstance

      A Serverless environment.

    • key: string

      The name of the environment variable to access.

    Returns Promise<VariableInstance | undefined>

    The VariableInstance matching the key, or undefined if no match is found.

getEnvironmentVariables

  • getEnvironmentVariables(context: { DOMAIN_NAME: string; ENVIRONMENT_SID: undefined | string; PATH: string; SERVICE_SID: undefined | string; getTwilioClient: any }, environment: EnvironmentInstance): Promise<VariableInstance[]>
  • Given a Serverless Context and an EnvironmentInstance (usually from getCurrentEnvironment), returns a list of defined environment variable instances.

    Usage: const envVars = await getEnvironmentVariables(context, environment);

    Parameters

    • context: { DOMAIN_NAME: string; ENVIRONMENT_SID: undefined | string; PATH: string; SERVICE_SID: undefined | string; getTwilioClient: any }

      The current Serverless context.

      • DOMAIN_NAME: string
      • ENVIRONMENT_SID: undefined | string
      • PATH: string
      • SERVICE_SID: undefined | string
      • getTwilioClient:function
        • getTwilioClient(options?: TwilioClientOptions): Twilio
        • Parameters

          • Optional options: TwilioClientOptions

          Returns Twilio

    • environment: EnvironmentInstance

      A Serverless environment.

    Returns Promise<VariableInstance[]>

    A list of environment variable instances.

setEnvironmentVariable

  • setEnvironmentVariable(context: { DOMAIN_NAME: string; ENVIRONMENT_SID: undefined | string; PATH: string; SERVICE_SID: undefined | string; getTwilioClient: any }, environment: EnvironmentInstance, key: string, value: string, override?: boolean): Promise<boolean>
  • For a given Serverless Context and EnvironmentInstance, set the environment variable named key to value.

    If the override parameter is true (the default), setting an existing environment variable will override its current value with the new one. If it is false, then this function will instead log a warning and return false.

    Usage: setEnvironmentVariable(context, envrionment, 'var', 'value');

    Parameters

    • context: { DOMAIN_NAME: string; ENVIRONMENT_SID: undefined | string; PATH: string; SERVICE_SID: undefined | string; getTwilioClient: any }

      The current Serverless context.

      • DOMAIN_NAME: string
      • ENVIRONMENT_SID: undefined | string
      • PATH: string
      • SERVICE_SID: undefined | string
      • getTwilioClient:function
        • getTwilioClient(options?: TwilioClientOptions): Twilio
        • Parameters

          • Optional options: TwilioClientOptions

          Returns Twilio

    • environment: EnvironmentInstance

      A Serverless environment.

    • key: string

      The name of the environment variable to set.

    • value: string

      The value to store in the environment variable.

    • override: boolean = true

      If true, allow overriding existing variables.

    Returns Promise<boolean>

    true if setting the environment variable succeeded, false if an error occurred

Generated using TypeDoc