//native
type Kustomer = {
apiKey: string;
};
/**
* Update message by ID
* Updates a message based on the unique message ID.
*/
export async function main(
auth: Kustomer,
id: string,
replace: string | undefined,
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;
spam?: false | true;
modifiedBy?: string;
lang?: string;
reactions?: {
subjectId: string;
subjectType: "customer" | "user";
name: "love";
createdAt?: string;
}[];
},
) {
const url = new URL(`https://api.kustomerapp.com/v1/messages/${id}`);
for (const [k, v] of [["replace", replace]]) {
if (v !== undefined && v !== "") {
url.searchParams.append(k, v);
}
}
const response = await fetch(url, {
method: "PUT",
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