Skip to content

monkeymars/medusa-plugin-whatsapp-cloud-api

Repository files navigation

medusa-plugin-whatsapp-cloud-api

dots-cover-template-min

WhatsApp Cloud API / Messaging plugin.

Learn more about how you can use this plugin in the documentaion.

Build & Test npm publish npm CodeQL NPM npm

Install Plugin

In the directory of your Medusa server, run the following command to install WhatsApp Cloud API plugin:

Yarn or NPM

npm install --save medusa-plugin-whatsapp-cloud-api
yarn add medusa-plugin-whatsapp-cloud-api

Options

Next, you need to add configurations for medusa-plugin-whatsapp-cloud-api plugin. In medusa-config.js add the following at the plugins array:

const plugins = [
  {
    resolve: `medusa-plugin-whatsapp-cloud-api`,
    options: {
      accessToken: "<Temporary or permanent access token>",
      WABA_ID: "<WhatsApp Business Account ID>",
      senderPhoneNumberId: "<Phone number ID>",
      graphAPIVersion: "<Graph API Version>",
    },
  },
];

Dynamic usage

You can resolve the WhatsApp service to dynamically send messages via WhatsApp Cloud API. Example:

sendMessageTemplate

router.get("/send-message-sample", async (req, res) => {
  const whatsappService = req.scope.resolve("whatsappService");

  const response = await whatsappService.sendMessageTemplate({
    templateId: "flight_confirmation", // your message templates
    recipientPhone: "+6281556750222",
    headerMessage: [
      {
        type: "image",
        image: {
          link: "https://<URL>",
        },
      },
    ],
    contentMessage: [
      { type: "text", text: "NYC" },
      { type: "text", text: "JFK" },
      {
        type: "date_time",
        date_time: {
          fallback_value: "December 24, 2022",
        },
      },
    ],
    lang: "en_US",
  });

  res.json({
    message: `message sent: ${response.status}`,
  });
});

sendLocation

whatsappService.sendLocation({
  name: "GBK Stadium",
  address: "Jl. Pintu Satu Senayan, Gelora, Kota Jakarta Pusat, DKI Jakarta",
  recipientPhone: "+6281556750222",
  latitude: -6.21844,
  longitude: 106.8018,
});

Preview: sendMessageTemplate

sample

Contributing

When contributing to this repository, please first discuss the change you wish to make via issue, email, or any other method with the owners of this repository before making a change.

Please note we have a code of conduct, please follow it in all your interactions with the project.

Pull Request Process

  1. Ensure any install or build dependencies are removed before the end of the layer when doing a build.
  2. Update the README.md with details of changes to the interface, this includes new environment variables, exposed ports, useful file locations and container parameters.
  3. Increase the version numbers in any examples files and the README.md to the new version that this Pull Request would represent. The versioning scheme we use is SemVer.
  4. You may merge the Pull Request in once you have the sign-off of two other developers, or if you do not have permission to do that, you may request the second reviewer to merge it for you.

Resources