Skip to content

felipeDS91/whatsapp-api

Repository files navigation

Logo

API to send messages through WhatsApp

GitHub top language Made by Repository size GitHub last commit Repository issues GitHub

About the project   |    Technologies   |    Getting started   |    How to contribute   |    License

Run in Insomnia

👨🏻‍💻 About the project

This API allow send messages using whatsapp through an API Rest. The project is separated by two main process, one for the API Rest and other responsible for check if there is new messages to send in the queue. Remember: This software is only for study purposes and you have to be careful to not be banned for sending spam using whatsapp. (Send spam through Whatsapp is illegal).

🚀 Technologies

Technologies that I used to develop this api

💻 Getting started

Import the Insomnia.json on Insomnia App or click on Run in Insomnia button

Requirements

Clone the project and access the folder

$ git clone https://github.com/felipeDS91/whatsapp-api.git && cd whatsapp-api

Follow the steps below

# Install the dependencies
$ yarn

# Creates a docker container or use your own mysql installation (changes the password)
$ docker run --name "whatsapp"  -e MYSQL_ROOT_PASSWORD="mysql_password" -p 3306:3306 -d mysql:5.7.30

# Creates a new mysql user (changes the username and password)
# To connect with mysql database you can use a tool like DBeaver for example
$ CREATE USER 'username'@'localhost' IDENTIFIED BY 'password';

# Make a copy of '.env.example' to '.env'
# and set with YOUR environment variables
$ cp .env.example .env

# Run the migrations and seeds
$ yarn typeorm migration:run

# Run this command to start the server in development mode
$ yarn dev:server

# Or you can run separately the API/WhatsApp message client
$ yarn dev:api
$ yarn dev:whatsapp

# Default credentials:
# username: admin
# password: 123456

# Well done, project is started!

👨🏻‍💻 Endpoints

  • /sessions: Sign in to get the access token .
  • /message: Send message to the queue.
Admin routes
  • /users: Manage the access to the API.
  • /tokens: Return a qrCode image and also render this QrCode on command line prompt to be read using an whatsapp and record that number to send new messages.

😖 Troubleshooting

  • Paas hosting (Heroku): This project uses whatsapp-web.js package that uses Puppeter and it is based on chrome. So if you are getting some log like this "...loading shared libraries: libnss3.so: cannot open shared object file..." you will have to install a "Buildpack" in your app. To do it, you have to access the app on Heroku and go to the menu "Settings" --> "Buildpacks" --> "Add buildpack", fill out the Buildpack URL with "jontewks/puppeteer" and click in "Save changes" button. And after your next deploy, this buildpack to use puppeter will be installed with your app.

  • Installation of linux dependencies: sudo apt install -y gconf-service libasound2 libatk1.0-0 libc6 libcairo2 libcups2 libdbus-1-3 libexpat1 libfontconfig1 libgcc1 libgconf-2-4 libgdk-pixbuf2.0-0 libglib2.0-0 libgtk-3-0 libnspr4 libpango-1.0-0 libpangocairo-1.0-0 libstdc++6 libx11-6 libx11-xcb1 libxcb1 libxcomposite1 libxcursor1 libxdamage1 libxext6 libxfixes3 libxi6 libxrandr2 libxrender1 libxss1 libxtst6 ca-certificates fonts-liberation libappindicator1 libnss3 lsb-release xdg-utils wget build-essential apt-transport-https libgbm-dev
    curl -sL https://deb.nodesource.com/setup_10.x | sudo -E bash -
    sudo apt install git nodejs yarn

🤔 How to contribute

  • Make a fork of this repository
# Fork using GitHub official command line
# If you don't have the GitHub CLI, use the web site to do that.

$ gh repo fork felipeDS91/whatsapp-api
# Clone your fork
$ git clone your-fork-url && cd whatsapp-api

# Create a branch with your feature
$ git checkout -b my-feature

# Make the commit with your changes
$ git commit -m 'feat: My new feature'

# Send the code to your remote branch
$ git push origin my-feature

After your pull request is merged, you can delete your branch

📝 License

This project is licensed under the MIT License - see the LICENSE file for details.


Made with 💜  by Felipe Douglas 👋 See my linkedin

Releases

No releases published

Packages

No packages published