Menu

Expand
Rate this page:

Runtime Client

The Twilio Runtime Client provides a simple and intuitive way of orchestrating the various parts of the Twilio Runtime. Using the Runtime Client, developers can reference other Functions to better organize their code, and access configuration stored in Assets.

Runtime Client Methods

getAssets()

The getAssets method returns an object of private Assets that can be used to retrieve files served on Twilio Assets.

For example, executing Runtime.getAssets() could return an object with the following private Assets:

{
  "/names.json": {
    "path": "/var/task/files/ZNdad14da2e70d2533f640cf362fec0609"
  },
  "/rickroll.mp3": {
    "path": "/var/task/files/ZNdfbfaf15a02e244fa11337548dabd9d0"
  },
  "/helper-method.js": {
    "path": "/var/task/files/ZN5d6d933785a76da25056328a5764d49b"
  }
}

Note that an Asset such as names.json will be returned with a key of "/names.json". To correctly retrieve the Asset and its path, the leading / and extension must be part of the key used to access the object returned by Runtime.getAssets().

For example: Runtime.getAssets()["/names.json"].path

getFunctions()

The getFunctions method returns an object of Functions that can be used to compose code hosted on Twilio Functions.

For example, executing Runtime.getFunctions() could return an object with the following Functions:

{
  "sms/reply": {
    "path": "/var/task/handlers/ZNdad14da2e70d2533f640cf362fec0609.js"
  },
  "helper": {
    "path": "/var/task/handlers/ZNdfbfaf15a02e244fa11337548dabd9d0.js"
  },
  "example-function": {
    "path": "/var/task/handlers/ZN5d6d933785a76da25056328a5764d49b.js"
  }
}

Note that, unlike an Asset, a Function such as sms/reply.js will be returned with a key of "sms/reply". To correctly retrieve the Function and its path, do not include characters such as a leading slash or the .js extension in the key used to access the object returned by Runtime.getFunctions().

For example: Runtime.getFunctions()["sms/reply"].path

Assets

The Asset object allows developers to load and reference files stored in Twilio Assets. This is ideal for configuration data or minified JavaScript libraries.

If you would like to include a JavaScript module that isn't available on npm, the best way to do so is to upload the module as a private Asset, then use getAssets in order to require the module as shown in the Load a module from an asset code example.

Asset Properties

Property Type Description
path String String specifying the location of the Asset
        
        
        
        Example of how to get the file path for an Asset

        Retrieve the path of an Asset

        Example of how to get the file path for an Asset
              
              
              
              Example of how to load a third party library stored in an Asset

              Load a module from an Asset

              Example of how to load a third party library stored in an Asset
                    
                    
                    
                    Example of how to read the contents of an Asset

                    Read the contents of an Asset

                    Example of how to read the contents of an Asset

                    Functions

                    The Function object enables developers to compose complex applications by allowing them to include and execute code stored in multiple Functions.

                    Function Properties

                    Property Type Description
                    path String String specifying the location of the Function
                          
                          
                          
                          Example of how to retrieve the file path for a Function

                          Retrieve the path for a Function

                          Example of how to retrieve the file path for a Function
                                
                                
                                
                                Example of how to include code from other Functions

                                Include code from a Function

                                Example of how to include code from other Functions
                                Rate this page:

                                Need some help?

                                We all do sometimes; code is hard. Get help now from our support team, or lean on the wisdom of the crowd by visiting our Twilio Community forums or browsing the Twilio tag on Stack Overflow.

                                      
                                      
                                      

                                      Thank you for your feedback!

                                      We are always striving to improve our documentation quality, and your feedback is valuable to us. How could this documentation serve you better?

                                      Sending your feedback...
                                      🎉 Thank you for your feedback!
                                      Something went wrong. Please try again.

                                      Thanks for your feedback!

                                      Refer us and get $10 in 3 simple steps!

                                      Step 1

                                      Get link

                                      Get a free personal referral link here

                                      Step 2

                                      Give $10

                                      Your user signs up and upgrade using link

                                      Step 3

                                      Get $10

                                      1,250 free SMSes
                                      OR 1,000 free voice mins
                                      OR 12,000 chats
                                      OR more