Edits history of script submission #13561 for ' Speak text to conference participants (telnyx)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Telnyx = {
    	apiKey: string
    }
    /**
     * Speak text to conference participants
     * Convert text to speech and play it to all or some participants.
     */
    export async function main(
    	auth: Telnyx,
    	id: string,
    	body: {
    		call_control_ids?: string[]
    		payload: string
    		payload_type?: 'text' | 'ssml'
    		voice: string
    		voice_settings?: { api_key_ref?: string }
    		language?:
    			| 'arb'
    			| 'cmn-CN'
    			| 'cy-GB'
    			| 'da-DK'
    			| 'de-DE'
    			| 'en-AU'
    			| 'en-GB'
    			| 'en-GB-WLS'
    			| 'en-IN'
    			| 'en-US'
    			| 'es-ES'
    			| 'es-MX'
    			| 'es-US'
    			| 'fr-CA'
    			| 'fr-FR'
    			| 'hi-IN'
    			| 'is-IS'
    			| 'it-IT'
    			| 'ja-JP'
    			| 'ko-KR'
    			| 'nb-NO'
    			| 'nl-NL'
    			| 'pl-PL'
    			| 'pt-BR'
    			| 'pt-PT'
    			| 'ro-RO'
    			| 'ru-RU'
    			| 'sv-SE'
    			| 'tr-TR'
    		command_id?: string
    	}
    ) {
    	const url = new URL(`https://api.telnyx.com/v2/conferences/${id}/actions/speak`)
    
    	const response = await fetch(url, {
    		method: 'POST',
    		headers: {
    			'Content-Type': 'application/json',
    			Authorization: 'Bearer ' + auth.apiKey
    		},
    		body: JSON.stringify(body)
    	})
    	if (!response.ok) {
    		const text = await response.text()
    		throw new Error(`${response.status} ${text}`)
    	}
    	return await response.json()
    }
    

    Submitted by hugo697 428 days ago