//native
type Intercom = {
apiVersion: string
token: string
}
/**
* Create a message
* You can create a message that has been initiated by an admin.
*/
export async function main(
auth: Intercom,
body:
| ({} & {
message_type?: 'in_app' | 'email'
subject?: string
body?: string
template?: string
from?: { type: 'admin'; id: number }
to?: { type: 'user' | 'lead'; id: string }
created_at?: number
create_conversation_without_contact_reply?: false | true
})
| ({} & {
message_type?: 'in_app' | 'email'
subject?: string
body?: string
template?: string
from?: { type: 'admin'; id: number }
to?: { type: 'user' | 'lead'; id: string }
created_at?: number
create_conversation_without_contact_reply?: false | true
})
) {
const url = new URL(`https://api.intercom.io/messages`)
const response = await fetch(url, {
method: 'POST',
headers: {
'Intercom-Version': auth.apiVersion,
'Content-Type': 'application/json',
Authorization: 'Bearer ' + auth.token
},
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 536 days ago