Skip to content

yoelpc4/whatsapp-service

Repository files navigation

Whatsapp Service

Whatsapp service to send message via API

Installation

  • Install project dependencies
yarn
  • Adjust env variables as needed

Serve

  • Serve for development
yarn dev
  • Build for production
yarn build

Features

Features are secured with basic auth, we need to pass header Authorization: Basic <credentials> on every request. Where credentials made of base64 encode username:password. The username and password are customizable via env variables.

In order to send a message, we need to create session from phone number in advance to initialize the whatsapp socket. Several endpoints required session to act as a sender, we need to attach the session to the request header for instance: session: +621234567890.

Public endpoints:

  • All endpoints on sessions module.

Protected endpoints:

  • All endpoints on persons module.
  • All endpoints on groups module.

Sessions Module

  • Create Session

Create sender session, returns QR code data URL. Replace the id with actual sender's phone number according to the whatsapp phone number format.

[POST] /sessions

Request body

{
  "id": "+621234567890"
}

Response body

{
  "data": {
    "qrCodeDataUrl": "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAARQAAAEUCAYAAADqcMl5AAAAAklEQVR4AewaftIAABIISURBVO3BQY4YybLgQDJR978yR0ufTQCJjFLrfbiZ/cFaa13wsNZalzystdYlD2utdcnDWmtd8rDWWpc8rLXWJQ9rrXXJw1prXfKw1lqXPKy11iUPa611ycNaa13ysNZalzystdYlD2utdckPH6n8TRUnKlPFpDJVnKi8UfGGyhsVk8obFScqJxWTylQxqbxRMam8UTGpvFExqZxUvKFyUjGp/E0VXzystdYlD2utdcnDWmtd8sNlFTepnKhMFZPKVDGpnFScqEwqX1RMKicVX6hMFZPKScWkMlW8ofJGxd9UcaIyVdxUcZPKTQ9rrXXJw1prXfKw1lqX/PDLVN6o+ELljYpJZVKZKqaK31QxqZxUfKFyojJVTBWTyknFGxWTyknFpPKFyknFpPKbVN6o+E0Pa611ycNaa13ysNZal/zwf0zFpDKpnFS8oTJVvKEyVUwqU8WkcqJyUnGiMlVMKlPFVDGpTCpTxRcVN1VMKicqJxWTyv8lD2utdcnDWmtd8rDWWpf88D+uYlKZKiaVE5WTiqliUpkqTiomlTcqJpWTiknlDZU3VKaKSWVSeaNiUpkqT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ycNaa13ysNZalzystdYlD2utdcnDWmtd8rDWWpc8rLXWJQ9rrXXJ/wP2YUmnne5UBQAAAABJRU5ErkJggg=="
  },
  "message": "Please scan the given QR code to continue!"
}
  • Find Session

Find existing sender session, returns message when exists.

[GET] /sessions/+621234567890

Response body

{
  "message": "Session +621234567890 is found"
}
  • Delete Session

Delete existing sender session, returns empty.

[DELETE] /sessions/+621234567890

Persons Module

  • Get Persons

Get persons in sender whatsapp contact, returns persons data.

[GET] /persons

Response body

[
  {
    "id": "[email protected]",
    "conversationTimestamp": 1668715224,
    "unreadCount": 1
  },
  {
    "id": "[email protected]",
    "conversationTimestamp": 1668715224,
    "unreadCount": 1
  }
]
  • Send Message

Send a message from sender to person, returns message.

[POST] /persons/send-message

Request body

{
  "whatsappId": "+622345678901",
  "text": "Hello world"
}

Response body

{
  "message": "Successfully send message"
}
  • Send Messages

Send bulk messages from sender to persons, returns message.

[POST] /persons/send-messages

Request body

{
  "messages": [
    {
      "whatsappId": "+622345678901",
      "text": "Hello world"
    },
    {
      "whatsappId": "+623456789012",
      "text": "Lorem ipsum dolor sit amet"
    }
  ]
}

Response body

{
  "message": "Successfully send messages"
}

Groups Module

  • Get Groups

Get groups in sender whatsapp contact, returns groups data.

[GET] /groups

Response body

[
  {
    "id": "[email protected]",
    "conversationTimestamp": 1668715224,
    "name": "Example Group 1",
    "unreadCount": 1
  },
  {
    "id": "[email protected]",
    "conversationTimestamp": 1668715224,
    "name": "Example Group 2",
    "unreadCount": 1
  }
]
  • Send Message

Send a message from sender to group, returns message.

[POST] /groups/send-message

Request body

{
  "whatsappId": "[email protected]",
  "text": "Hello world"
}

Response body

{
  "message": "Successfully send message"
}
  • Send Messages

Send bulk messages from sender to groups, returns message.

[POST] /groups/send-messages

Request body

{
  "messages": [
    {
      "whatsappId": "[email protected]",
      "text": "Hello world"
    },
    {
      "whatsappId": "[email protected]",
      "text": "Lorem ipsum dolor sit amet"
    }
  ]
}

Response body

{
  "message": "Successfully send messages"
}

About

Whatsapp service to send message via API

Resources

License

Code of conduct

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published