Twilio Assets is a static file hosting service that allows developers to quickly upload and serve the files needed to support their applications. With Twilio Assets you can host your files that support web, voice, and messaging applications. Twilio Assets is frequently used to host .mp3
audio files used in TwiML and Studio Flows, to serve images sent through MMS, or to store configuration used by Twilio Functions.
Twilio provides you with three different types of Assets: public, protected, and private. The primary difference between the types is how they are accessed:
If you would like to learn more about Asset visibility, we have a document that goes over the distinctions between public, protected, and private assets in greater detail.
Anyone with the URL to a public asset will be able to access it. Therefore, customers should be thoughtful about what data they include in a public asset.
Asset files are uploaded as is, with all metadata persisted. If your Asset files contain metadata, that will be stored with the file. An example would be EXIF metadata stored with an image. If you are making files available, please note that metadata is persisted and not removed/changed by the Assets product in any way.
Start by opening one of your existing Services, or by creating a new one. Once you're in the Functions Editor UI for your Service there are three points of interest:
_26exports.handler = (context, event, callback) => {_26 // Access the NodeJS Helper Library by calling context.getTwilioClient()_26 const client = context.getTwilioClient();_26 // Query parameters or values sent in a POST body can be accessed from `event`_26 const from = event.From || '+15017122661';_26 const to = event.To || '+15558675310';_26 const body = event.Body || 'Ahoy, World!';_26_26 client.messages_26 .create({_26 to,_26 from,_26 body,_26 // You will get a 403 if you try to view this image, but Twilio will_26 // be able to access it and send it as part of the outgoing MMS_26 mediaUrl: 'https://twilio-assets-1967.twil.io/grumpy.jpg',_26 })_26 .then((message) => {_26 console.log(`Success! MMS SID: ${message.sid}`);_26 return callback(null, message.sid);_26 })_26 .catch((error) => {_26 console.error(error);_26 return callback(error);_26 });_26};
Similarly, suppose you have audio or messaging to include in your Studio Flow, but don't want that audio to be accessible to the entire internet. If the audio were uploaded as protected Asset, you could then reference its URL in the Studio Say/Play widget, and the audio will play for anybody that hits that part of your Flow.
For example, if the audio were a protected Asset deployed at https://twilio-assets-1967.twil.io/sensitive-message.mp3
, it could be referenced in your Studio Flow as shown below: