asset

Application Assets (e.g. sound files for an IVR)

Summit applications can use assets which are files specific to the application. The asset library assists in creating reusable objects that reference the files associated with your app. They are often used in the channel.gather and channel.play functions.

-- In this example, you would need to have `menu.mp3` and `invalid.mp3` in your
-- assets folder. Let's assume:
--      * menu.mp3 is a greeting telling the caller to press 1 or 2
--      * invalid.mp3 is a message informing the caller that they did not press 1 or 2

local log = require("summit.log")
local asset = require("summit.asset")

-- The `asset` object is callable
local menu_greeting = asset("menu.mp3")

-- Or you can use `asset.get()` to do the same thing
local invalid_message = asset.get("invalid.mp3")

function prompt()
    -- The invalidPlay argument here will play if the gather is invalid
    local digit = channel.gather({play=menu_greeting,
                                  invalidPlay=invalid_message,
                                  maxDigits=1,
                                  timeout=2})

    log.info("The caller pressed menu option"..digit)

    if digit == "1" then
        channel.say("You pressed 1")
    elseif digit == "2" then
        channel.say("You pressed 2")
    else
        -- Assume we only allow 1 or 2 as valid options but the gather was valid.
        -- We can reuse the asset here and perform some other business logic.
        channel.play(invalid_message)
    end
end

channel.answer()

prompt()

channel.say("Good bye")
channel.hangup()

In this example, we declared two assets separately from the logic of our function and were able to use our invalid.mp3 twice. This avoids duplicating the name of an asset throughout your code, so if we were to update the application to use a new file, it would only require that we change it in one place.

Classes

Name Summary
Asset

Represents a reference to an asset. This can be passed to channel.play and channel.gather, just like a speech object or outside URL.

Functions

Name Summary
get

Creates a reference to an asset

Classes : asset

Asset

Represents a reference to an asset. This can be passed to channel.play and channel.gather, just like a speech object or outside URL.

Functions : asset

get(filename, eager)

Creates a reference to an asset

Parameters
Name Type Default Summary

filename

string

A filename relative to the assets folder in the root of the application.

eager

boolean

false

Determines whether this file will be prepared immediately or if Summit will wait until the file is first played. Unless you have a specific reason, we recommend using the default for this.

Returns
Type Summary

Asset

A reference to the asset

Usage
-- Refer to the example above for a more detail

local asset = require("summit.asset")

-- Create a reusable `asset` object that references a file
local invalid_message = asset.get("invalid.mp3")