0

Send Reaction

by
Published today

React to a received message with an emoji.

Script whatsapp_business Verified

The script

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

3
/**
4
 * Send Reaction
5
 * React to a received message with an emoji.
6
 */
7
export async function main(
8
  auth: RT.WhatsappBusiness,
9
  to: string,
10
  message_id: string,
11
  emoji: string
12
) {
13
  const apiVersion = auth.api_version || "v25.0"
14
  const url = new URL(
15
    `https://graph.facebook.com/${apiVersion}/${auth.phone_number_id}/messages`
16
  )
17

18
  const response = await fetch(url, {
19
    method: "POST",
20
    headers: {
21
      Authorization: `Bearer ${auth.token}`,
22
      "Content-Type": "application/json",
23
      Accept: "application/json",
24
    },
25
    body: JSON.stringify({
26
      messaging_product: "whatsapp",
27
      recipient_type: "individual",
28
      to,
29
      type: "reaction",
30
      reaction: {
31
        message_id,
32
        emoji,
33
      },
34
    }),
35
  })
36

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

41
  return await response.json()
42
}
43