0
Get message stats
One script reply has been approved by the moderators Verified
Created by hugo697 40 days ago Viewed 7 times
0
Submitted by hugo697 Bun
Verified 40 days ago
1
//native
2
type Actimo = {
3
	apiKey: string
4
}
5

6
export async function main(
7
	auth: Actimo,
8
	id: string,
9
	bounce: string | undefined,
10
	moduleDetails: string | undefined,
11
	modules: string | undefined,
12
	open: string | undefined,
13
	unique: string | undefined,
14
	since: string | undefined
15
) {
16
	const url = new URL(`https://actimo.com/api/v1/messages/${id}/stats`)
17

18
	for (const [k, v] of [
19
		['bounce', bounce],
20
		['moduleDetails', moduleDetails],
21
		['modules', modules],
22
		['open', open],
23
		['unique', unique],
24
		['since', since]
25
	]) {
26
		if (v !== undefined && v !== '' && k !== undefined) {
27
			url.searchParams.append(k, v)
28
		}
29
	}
30

31
	const response = await fetch(url, {
32
		method: 'GET',
33
		headers: {
34
			'api-key': auth.apiKey
35
		},
36
		body: undefined
37
	})
38

39
	if (!response.ok) {
40
		const text = await response.text()
41
		throw new Error(`${response.status} ${text}`)
42
	}
43

44
	return await response.json()
45
}
46