Edits history of script submission #11189 for ' Update a conversation (intercom)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Intercom = {
    	apiVersion: string
    	token: string
    }
    /**
     * Update a conversation
     * 
    You can update an existing conversation.
    
    {% admonition type="info" name="Replying and other actions" %}
    If you want to reply to a coveration or take an action such as assign, unassign, open, close or snooze, take a look at the reply and manage endpoints.
    {% /admonition %}
    
    
     */
    export async function main(
    	auth: Intercom,
    	id: string,
    	display_as: string | undefined,
    	body: { read?: false | true; custom_attributes?: {} }
    ) {
    	const url = new URL(`https://api.intercom.io/conversations/${id}`)
    	for (const [k, v] of [['display_as', display_as]]) {
    		if (v !== undefined && v !== '' && k !== undefined) {
    			url.searchParams.append(k, v)
    		}
    	}
    	const response = await fetch(url, {
    		method: 'PUT',
    		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