Code Monkey home page Code Monkey logo

adonisjs-whatsapp's Introduction

I stand with Palestine

adonisjs-whatsapp

What's this

This package makes it easy for developers to access the WhatsApp Cloud API service in the AdonisJS 5 application.

Getting Started

Please create and configure your Facebook WhatsApp application by following the "Get Started" section of the official guide.

Setup

Install the package using npm or yarn:

npm i adonisjs-whatsapp
# or
yarn add adonisjs-whatsapp

Then, configure the package using the configure command:

node ace configure adonisjs-whatsapp

After executing the above command, a config/whatsapp.ts file will be created, where you can define the WhatsApp Cloud API.

An important step is to set environment variables in your .env and validate them in the env.ts file.

WABA_ID: Env.schema.string(),
WABA_TOKEN: Env.schema.string(),
WABA_VERIFY: Env.schema.string(),

Usage

The package supports events that are triggered when receiving a webhook from WhatsApp, some of which can be seen here.

The event can be subscribed to via the start/whatsapp.ts file.

// start/whatsapp.ts

import WhatsApp from '@ioc:Adonis/Addons/WhatsApp'

WhatsApp.on('message:text', function (message) {
  // TODO: do whatever you want
})

To send text, images, and more, use the same singleton in your preload or controller file.

// app/Controllers/Http/ExampleController.ts

import WhatsApp from '@ioc:Adonis/Addons/WhatsApp'
import { HttpContextContract } from '@ioc:Adonis/Core/HttpContext'

export default class ExampleController {
  public async example(_ctx: HttpContextContract) {
    await WhatsApp.sendText(628123456789, 'Lorem ipsum dolor sit amet.')
  }
}

Features

  • Mark messages as read
  • Upload media to the WhatsApp server
  • Download media from the WhatsApp server
  • Send text messages
  • Send images
  • Send documents
  • Send audios
  • Send videos
  • Send stickers
  • Send locations
  • Send template messages
  • Send contacts
  • Send reply button messages
  • Send list messages
  • Include a Webhook Endpoint 
  • Event listener when receiving a webhook

Changelog

Please see the CHANGELOG for more information on what has changed recently.

License

The MIT License (MIT). Please see LICENSE file for more information.

Disclaimer

This package is not officially maintained by Facebook. WhatsApp and Facebook trademarks and logos are the property of Meta Platforms, Inc.

adonisjs-whatsapp's People

Contributors

sooluh avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

Forkers

falahdev

adonisjs-whatsapp's Issues

Whatsapp PhoneId is bigger and thus getting changed

Description

Phone number id is getting changed when it 18 Character Long. I am passing 122097329108006499 which is getting changed to 122097329108006500

both number are beyond the safe integer range in JavaScript. JavaScript uses a 64-bit floating-point representation, which provides around 15-17 decimal digits of precision. Numbers larger than 2^53 - 1 (which is approximately 9 quadrillion) may not be represented exactly.

Solution

Just Change the type to string rather then number it will solve the issue. 😁

Package version

0.2.4

Error Message & Stack Trace

Unsupported post request. Object with ID '122097329108006500' does not exist, cannot be loaded due to missing permissions, or does not support this operation. Please read the Graph API documentation at https://developers.facebook.com/docs/graph-api
at WhatsAppClient.send (/Users/yashkumar/Documents/Projects/ark_server/node_modules/adonisjs-whatsapp/build/src/WhatsAppClient.js:32:19)

Relevant Information

Support for v17.0 SDK

I tried with v17.0 but I guess it's not working properly

Template message is working not TextMessage is not working.

New Phone Number By Whatsapp is Bigger in Length

Description

Phone number id is getting changed when it 18 Character Long. I am passing 122097329108006499 which is getting changed to 122097329108006500

both number are beyond the safe integer range in JavaScript. JavaScript uses a 64-bit floating-point representation, which provides around 15-17 decimal digits of precision. Numbers larger than 2^53 - 1 (which is approximately 9 quadrillion) may not be represented exactly.

Solution

Just Change the type to string rather then number it will solve the issue. 😁

Package version

0.2.4

Error Message & Stack Trace

Unsupported post request. Object with ID '122097329108006500' does not exist, cannot be loaded due to missing permissions, or does not support this operation. Please read the Graph API documentation at https://developers.facebook.com/docs/graph-api
at WhatsAppClient.send (/Users/yashkumar/Documents/Projects/ark_server/node_modules/adonisjs-whatsapp/build/src/WhatsAppClient.js:32:19)

Relevant Information

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.