Edits history of script submission #11160 for ' Reply to a ticket (intercom)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Intercom = {
    	apiVersion: string
    	token: string
    }
    /**
     * Reply to a ticket
     * You can reply to a ticket 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' | 'quick_reply'
    				type: 'admin'
    				body?: string
    				admin_id: string
    				created_at?: number
    				reply_options?: { text: string; uuid: string }[]
    				attachment_urls?: string[]
    		  }
    ) {
    	const url = new URL(`https://api.intercom.io/tickets/${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