//native
type Kustomer = {
apiKey: string;
};
/**
* Update message attributes by ID
* Updates attributes for a message based on the unique message ID.
*/
export async function main(
auth: Kustomer,
id: string,
body: {
conversation?: string;
externalId?: string;
preview?: string;
subject?: string;
status?: "sent" | "received" | "error";
error?: {
status?: number;
code?: string;
title?: string;
detail?: string;
source?: {};
meta?: {};
links?: {};
};
errorAt?: string;
sentAt?: string;
size?: number;
attachments?: {
_id: string;
name: string;
contentType: string;
contentLength: number;
sourceId?: string;
}[];
meta?: {};
custom?: {};
related?: string;
sentiment?: { polarity: 0 | 1 | -1; confidence: number };
createdAt?: string;
modifiedAt?: string;
updatedAt?: string;
createdBy?: string;
modifiedBy?: string;
lang?: string;
},
) {
const url = new URL(`https://api.kustomerapp.com/v1/messages/${id}`);
const response = await fetch(url, {
method: "PATCH",
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 235 days ago