0

Mark Message as Read

by
Published today

Mark a received message as read (blue ticks), optionally showing a typing indicator that lasts up to 25 seconds.

Script whatsapp_business Verified

The script

Submitted by hugo989 Typescript (fetch-only)
Verified 4 hours ago
1
//native
2

3
/**
4
 * Mark Message as Read
5
 * Mark a received message as read (blue ticks), optionally showing a typing indicator that lasts up to 25 seconds.
6
 */
7
export async function main(
8
  auth: RT.WhatsappBusiness,
9
  message_id: string,
10
  show_typing_indicator: boolean | undefined
11
) {
12
  const apiVersion = auth.api_version || "v25.0"
13
  const url = new URL(
14
    `https://graph.facebook.com/${apiVersion}/${auth.phone_number_id}/messages`
15
  )
16

17
  const payload: { [key: string]: any } = {
18
    messaging_product: "whatsapp",
19
    status: "read",
20
    message_id,
21
  }
22
  if (show_typing_indicator) {
23
    payload.typing_indicator = { type: "text" }
24
  }
25

26
  const response = await fetch(url, {
27
    method: "POST",
28
    headers: {
29
      Authorization: `Bearer ${auth.token}`,
30
      "Content-Type": "application/json",
31
      Accept: "application/json",
32
    },
33
    body: JSON.stringify(payload),
34
  })
35

36
  if (!response.ok) {
37
    throw new Error(`${response.status} ${await response.text()}`)
38
  }
39

40
  return await response.json()
41
}
42