npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

amon-andromeda

v5.0.0

Published

Andromeda is a Baileys-based lib, designed to be an easy abstraction of Baileys. Clear and concise, easy-to-use methods with a quick boot setup.

Downloads

25

Readme

Amon-Andromeda

Install

If you want the qrcode to be printed in the terminal, you will need to download the qrcode-terminal package, which is not included for licensing reasons.

yarn add amon-andromeda

Than you can import using:

import { Andromeda } from 'amon-andromeda';
//or
const { Andromeda } = require('amon-andromeda');

Documentations

  • Usage
  • Temporary data storage
  • Methods
  • Listening to events
  • Downloading media files
  • Running with docker

Usage

To be able to run the code first a connection to a mysql database is needed, just start a database locally or in the cloud and pass the connection data, no further configuration is needed, Amon-Andromeda will take care of the rest.

const { Andromeda } = require('amon-andromeda');
const path = require('path');

(async () => {

  const client = await Andromeda({
    sessionName: 'andromeda',
    TemporaryStoragePath: path.resolve(__dirname, '.', 'storage'),
    downloadMediaPath: path.resolve(__dirname, '..', 'media'),
    IgnoreBroadCastMessages: true,
    IgnoreGroupsMessages: true,
    IgnoreServer_ACK: true,
    qrCodeInTerminal: true,
    qrcodoPath: path.resolve(__dirname, '.', 'image', 'andromeda_qrcode.png'),
    connectionStorage: {
      dbname: 'andromeda',
      host: 'host',
      pass: 'pass',
      user: 'user'
    },
    onStatusChange: (connectionStatus) => console.log(connectionStatus),
    onMessage: (messages) => {

      console.log(JSON.stringify(messages, undefined, 2))

    }
  });

  await client.sendSimpleMessage('hello word!', '551197070879');

})();

Temporary data storage

Some Baileys methods require the entire body of the message sent and received so you need to save the data of all messages somewhere. Baileys itself has an internal module that helps the developer with this task, but this is just a quick fix, since this data is all saved in memory, so if your application is running for a long time and many messages are exchanged, your application will slow down as time goes on and the documentation itself warns the developer that this is not a good approach. So thinking about it, we made a slightly different logic. We save the data of all messages exchanged inside a .JSON file, and when we reach a limit of 500 messages, we migrate this data at once to a mysql database. Therefore, all you need to do is pass the path of the folder, where in the example above we call storage, but you can call it whatever you want, the path of this folder will be used to create the .JSON file where the message data will be saved.

TemporaryStoragePath: path.resolve(__dirname, '.', 'storage')

Methods

Sending a simple message.

await client.sendSimpleMessage('hello word!', '551197070879');

Replying to a message.

await client.replyMessage('551197070879', 'hello word!', 'BAE57B9147270DE0');

Checking if a number exists as valid number.

await client.verifyExistenceNumber('551197070879');

Sending a gif or video.

await client.sendGifOrVideoMessage(path.resolve(__dirname, 'file.mp4'), '551197070879', 'hello word!', true);

NOTE: if the last parameter is true, this means that the message gonna be sent how gif.

Sending a picture.

await client.sendImage(path.resolve(__dirname, 'file.png'), '551197070879', 'Hello word!');

Taking a picture of a contact.

await client.getImageContact('551197070879', false);

NOTE: if the second parameter is true, the method will try to get the profile picture of a group.

Blocking a contact.

await client.blockContact('551197070879');

Unlocking a contact.

await client.unBlockContact('551197070879');

Deleting a message for everyone.

await client.deleteMessageForEveryone('551197070879', 'BAE57B9147270DE0', false);

NOTE: The third parameter signals whether the message is a group message or not.

Sending audio files.

await client.sendAudioMedia(path.resolve(__dirname, 'file.mp3'), '551197070879', false);

NOTE: if the last parameter is false the message will be sent as an audio file, if true it will be sent with a voice message.

Sending a list.

await client.sendListMessage('551197070879', {
  text: 'text',
  buttonText: 'buttonText',
  footer: 'footer',
  title: 'title',
  sections: [
    {
      title: 'section title',
      rows: [
        {
          title: 'Option one',
          rowId: 'optionone',
          description: 'description'
        }
      ]
    }
  ]
});

Capturing device information.

await client.getDeviceInformation();

NOTE: for the method to work correctly, an established connection is required.

Listening to events

Every time a new message is received on your device, an event will be triggered, as a parameter it will have an object containing the message body. The onMessage() method is initialized as an andromeda() parameter, as shown in the usage example at the beginning of the article

onMessage(message) => console.log(JSON.stringfy(message, undefined, 2))

Listening for connection status change event. Every time the connection status changes the onStatusChange() event will be triggered, the parameter of this method contains the status for which it was signaled. Thinking about something simpler and more concise, the signaling status was summarized in just two values ['Connected', 'WaitinLogin']. The onStatusChange() method is initialized in the same way as the previous one.

onStatusChange(connectionStatus) => console.log(connectionStatus)

Downloading media files

Amon-andromeda does all the file handling processes for you. All you need to do is pass the path of the folder where you want the data to be saved in the downloadMediaPath property.

downloadMediaPath: path.resolve(__dirname, '..', 'media')

NOTE: when the download finishes, you will receive the fileNameDownloaded property along with the message body data that comes as a parameter in the onMessage event method.

Running with docker

Just like the volume configuration you do for your database in the docker-compose file, the same is necessary for Amon-Andromeda. Earlier in this article we talked about the TemporaryStoragePath initialization property, so that no data loss occurs you should make a volume for the path you specified in the property.