Skip to content

Instantly share code, notes, and snippets.

// Imports global types
import '@twilio-labs/serverless-runtime-types'
// Fetches specific types
import {
Context,
ServerlessCallback,
ServerlessFunctionSignature,
} from '@twilio-labs/serverless-runtime-types/types'
import axios, {AxiosResponse} from 'axios'
import FormData from 'form-data'
@kuschanton
kuschanton / ring_on_task.ts
Created June 10, 2022 12:13
Twilio Flex: code snippet to be used in a Flex Plugin to make browser play ringtone when a task comes in
Flex.Manager.getInstance().workerClient.on('reservationCreated', (reservation: Reservation) => {
console.log('reservation', reservation)
let mediaId = Flex.AudioPlayerManager.play({
url: 'https://api.twilio.com/cowbell.mp3',
repeatable: true,
})
reservation.on('accepted', () => Flex.AudioPlayerManager.stop(mediaId))
reservation.on('canceled', () => Flex.AudioPlayerManager.stop(mediaId))
reservation.on('completed', () => Flex.AudioPlayerManager.stop(mediaId))
// Imports global types
import '@twilio-labs/serverless-runtime-types'
// Fetches specific types
import {
Context,
ServerlessCallback,
ServerlessFunctionSignature,
} from '@twilio-labs/serverless-runtime-types/types'
type OptOut = {