//native
type Telnyx = {
apiKey: string
}
/**
* Send an RCS message
*
*/
export async function main(
auth: Telnyx,
body: {
bot_id: string
to: string
messaging_profile_id: string
type?: 'RCS'
agent_message: {
content_message?: {
suggestions?: {
reply?: { text?: string; postback_data?: string }
action?: {
text?: string
postback_data?: string
fallback_url?: string
dial_action?: { phone_number: string }
view_location_action?: {
lat_long?: { latitude: number; longitude: number }
label?: string
query?: string
}
create_calendar_event_action?: {
start_time?: string
end_time?: string
title?: string
description?: string
}
open_url_action?: {
url: string
application: 'OPEN_URL_APPLICATION_UNSPECIFIED' | 'BROWSER' | 'WEBVIEW'
webview_view_mode: 'WEBVIEW_VIEW_MODE_UNSPECIFIED' | 'FULL' | 'HALF' | 'TALL'
description?: string
}
share_location_action?: {}
compose_action?: {
compose_text_message?: { phone_number: string; text?: string }
compose_recording_message?: {
phone_number?: string
type:
| 'COMPOSE_RECORDING_ACTION_TYPE_UNSPECIFIED'
| 'ACTION_TYPE_AUDIO'
| 'ACTION_TYPE_VIDEO'
}
}
}
}[]
text?: string
rich_card?: {
carousel_card?: {
card_width?: 'CARD_WIDTH_UNSPECIFIED' | 'SMALL' | 'MEDIUM'
card_contents?: {
title?: string
description?: string
media?: {
height?: 'TALL' | 'MEDIUM' | 'HEIGHT_UNSPECIFIED' | 'SHORT'
content_info?: {
file_url?: string
thumbnail_url?: string
force_refresh?: false | true
}
}
suggestions?: {
reply?: { text?: string; postback_data?: string }
action?: {
text?: string
postback_data?: string
fallback_url?: string
dial_action?: { phone_number: string }
view_location_action?: {
lat_long?: { latitude: number; longitude: number }
label?: string
query?: string
}
create_calendar_event_action?: {
start_time?: string
end_time?: string
title?: string
description?: string
}
open_url_action?: {
url: string
application: 'OPEN_URL_APPLICATION_UNSPECIFIED' | 'BROWSER' | 'WEBVIEW'
webview_view_mode: 'WEBVIEW_VIEW_MODE_UNSPECIFIED' | 'FULL' | 'HALF' | 'TALL'
description?: string
}
share_location_action?: {}
compose_action?: {
compose_text_message?: {
phone_number: string
text?: string
}
compose_recording_message?: {
phone_number?: string
type:
| 'COMPOSE_RECORDING_ACTION_TYPE_UNSPECIFIED'
| 'ACTION_TYPE_AUDIO'
| 'ACTION_TYPE_VIDEO'
}
}
}
}[]
}[]
}
standalone_card?: {
card_orientation: 'CARD_ORIENTATION_UNSPECIFIED' | 'HORIZONTAL' | 'VERTICAL'
thumbnail_image_alignment: 'THUMBNAIL_IMAGE_ALIGNMENT_UNSPECIFIED' | 'LEFT' | 'RIGHT'
card_content: {
title?: string
description?: string
media?: {
height?: 'TALL' | 'MEDIUM' | 'HEIGHT_UNSPECIFIED' | 'SHORT'
content_info?: {
file_url?: string
thumbnail_url?: string
force_refresh?: false | true
}
}
suggestions?: {
reply?: { text?: string; postback_data?: string }
action?: {
text?: string
postback_data?: string
fallback_url?: string
dial_action?: { phone_number: string }
view_location_action?: {
lat_long?: { latitude: number; longitude: number }
label?: string
query?: string
}
create_calendar_event_action?: {
start_time?: string
end_time?: string
title?: string
description?: string
}
open_url_action?: {
url: string
application: 'OPEN_URL_APPLICATION_UNSPECIFIED' | 'BROWSER' | 'WEBVIEW'
webview_view_mode: 'WEBVIEW_VIEW_MODE_UNSPECIFIED' | 'FULL' | 'HALF' | 'TALL'
description?: string
}
share_location_action?: {}
compose_action?: {
compose_text_message?: {
phone_number: string
text?: string
}
compose_recording_message?: {
phone_number?: string
type:
| 'COMPOSE_RECORDING_ACTION_TYPE_UNSPECIFIED'
| 'ACTION_TYPE_AUDIO'
| 'ACTION_TYPE_VIDEO'
}
}
}
}[]
}
}
}
content_info?: {
file_url?: string
thumbnail_url?: string
force_refresh?: false | true
}
}
event?: { event_type?: 'TYPE_UNSPECIFIED' | 'IS_TYPING' | 'READ' }
expire_time?: string
ttl?: string
}
}
) {
const url = new URL(`https://api.telnyx.com/v2/messsages/rcs`)
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