Edits history of script submission #11159 for ' Reply to a conversation (intercom)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Intercom = {
    	apiVersion: string
    	token: string
    }
    /**
     * Reply to a conversation
     * You can reply to a conversation with a message from an admin or on behalf of a contact, or with a note for admins.
     */
    export async function main(
    	auth: Intercom,
    	id: string,
    	body:
    		| {
    				message_type: 'comment'
    				type: 'user'
    				body: string
    				created_at?: number
    				attachment_urls?: string[]
    		  }
    		| {
    				message_type: 'comment'
    				type: 'user'
    				body: string
    				created_at?: number
    				attachment_urls?: string[]
    		  }
    		| {
    				message_type: 'comment'
    				type: 'user'
    				body: string
    				created_at?: number
    				attachment_urls?: string[]
    		  }
    		| {
    				message_type: 'comment' | 'note'
    				type: 'admin'
    				body?: string
    				admin_id: string
    				created_at?: number
    				attachment_urls?: string[]
    				attachment_files?: {
    					content_type?: string
    					data?: string
    					name?: string
    				}[]
    		  }
    ) {
    	const url = new URL(`https://api.intercom.io/conversations/${id}/reply`)
    
    	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