Giter Site home page Giter Site logo

gfaraj / super-bot Goto Github PK

View Code? Open in Web Editor NEW
22.0 9.0 13.0 645 KB

A simple but extensible bot written in Node (with Whatsapp, Slack, and Discord interfaces)

License: MIT License

JavaScript 99.25% Dockerfile 0.59% Shell 0.16%
bot-service bot whatsapp-web sticker plugins

super-bot's Introduction

Actions Status

super-bot

A simple but extensible bot written in Node.js. Currently there are Whatsapp, Slack, and Discord interfaces, but any messaging platform can be supported by creating a client for it (e.g FB Messenger, MS Teams, IRC).

Docker

Running the bot service as a docker container is not yet supported due to incompatibility issues with the database provider. The bot clients are all dockerized, though, and here is a handy docker-compose file to quickly start all of them.

Installing from source

Clone this repository:

git clone https://github.com/gfaraj/super-bot.git

and install its dependencies by running:

npm install

Make sure you have npm and Node 10 or newer installed.

Starting the bot

You can run the bot service with the following command:

npm run start

The bot service starts a web server on port 3000 (which is configurable) and accepts POST requests on "/message" with the body being JSON data representing a message object. The bot then will run that message through any commands that are supported and sends back the response. This makes it really easy to have any number of interfaces tied to the same bot service. Currently there's no security to restrict access to this endpoint so be aware that anyone could post messages to the bot.

Configuration

The bot uses a JSON configuration file located in the ./config folder. See the config package documentation for more information. The Whatsapp client is also configured this way.

Clients

The same bot service can be utilized through different clients. The clients are how users interface with the bot service. They handle all the platform-specific tasks like listening for new messages and transforming them into a standard message object for the bot service.

Repo Description
super-bot-whatsapp Chat interface for Whatsapp
super-bot-slack Chat interface for Slack
super-bot-discord Chat interface for Discord

Plugins

The bot is driven by plugins. Each plugin can define any number of commands that it supports (a command can only be supported by a single plugin). A plugin can also subscribe to be called whenever a message has not been handled by any command (for example, as a fallback). It's required that a plugin export a default function that will be called during initialization.

export default function(bot) {
    bot.command('echo', (bot, message) => {
        bot.respond({ text : message.text, attachment : message.attachment });   // just respond back with the same message.
    });
    bot.raw((bot, message, next) => {
        if (message.text.includes('foo')) {  // check if we can handle this raw message.
            bot.respond('bar');
        }
        else {
            next();  // call next if your plugin can't handle this message.
        }
    });
}

record

This plugin allows you (and your friends) to record key-value pairs with optional attachments (currently only images and Whatsapp stickers are supported). The recordings are scoped per chat. There is a plan to support global recordings in the future.

record <name> <value>

The value is optional if an attachment is provided.

The plugin also registers the "forget" command to remove a recording. Only you or the recording's author are allowed to do this. It also registers the "recordings" command which sends a list of all existing recordings that match a given string (or all if no string is provided).

Examples:

record hi Hello everyone!

After doing that, when the bot is given the command "hi" it will respond with "Hello everyone!".

(as a reply to an image message)
record kids

The Whatsapp client will append any replied message to the current command, so in the example above it will save a "kids" recording with the image attachment. Then when the bot is given the "kids" command, it will send that image.

record stocks !google stock msft

This is an unofficial way to write shortcuts to other commands. After the command above, if given the "stocks" command, the bot will respond with "!google stock msft" and it will then respond to that command. In the future, a proper command chaining feature based on piping is planned.

translate

This plugin translates a given text into a target language like so:

translate es Hi, how are you doing?

It takes a two-letter locale as the first parameter and the text to translate after it.

This uses the Google Translate API to perform the translation. You need to set up a Google Cloud project with Translate support to be able to use this plugin. There is a cost to this if the free quotas are exceeded, so be mindful of that.

google

This plugin will perform a Google search and return the first 2 results. It's currently scraping the google search results (using puppeteer to process and render the initial web page, then using cheerio to grab the information). This is not permitted by Google so use at your own risk.

google game of thrones

The response is something like:

1) https://www.hbo.com/game-of-thrones
2) https://en.wikipedia.org/wiki/Game_of_Thrones

This plugin also exposes a "gimg" command that performs a Google Image Search and sends back the first image result (sends the actual image, not just a link). Currently it's returning a low-res image but it's possible to adjust it to get the original image.

evaluate

This plugin will evaluate an expression and respond with the result. It exposes two commands, eval and calc. The eval command accepts any type of (limited - it uses safe-eval) javascript expression, while the calc command will only work with numeric expressions.

eval 'Hello' + ' world!'
calc 10 + 20 / 2
calc 15 - sqrt(4)

Responds with:

Hello world!
20
13

sticker

This plugin provides utilities related to Whatsapp stickers. The "stickerize" command will take any image and convert it to a Whatsapp sticker.

(as a reply to an image message)
stickerize

This would send a message with the quoted image as a sticker.

code

This plugin allows you to build and run code in many languages. It will respond with any build errors or any output generated by your program. You can use this plugin like this:

!code -l<language> <code text>

Examples:

!code -lc# public static class P { public static void Main() { System.Console.WriteLine("Hello, world!\n"); } }

!code -lgo package main import "fmt" func main() { fmt.Printf(''Have fun!") }

There are a couple of shortcuts for C# and C++ currently and more can be added easily:

!cs public static class P { public static void Main() { System.Console.WriteLine("Hello, world!\n"); } }

!c++ #include<iostream>
int main() { std::cout << "Hey there!\n"; }

The plugin also supports passing in a code file as an attachment.

Other commands

There are many other commands available like remindme, trivia, poll, factoid, and several imaging utilities.

Contribution

Contribution of any kind is welcome! Please feel free to create your own plugins for the bot service, chat interfaces, features or bug fixes. Fork the repository, create your own branch and submit pull requests.

Disclaimer

This project was done for educational purposes. This code is in no way affiliated with, authorized, maintained, sponsored or endorsed by WhatsApp or any of its affiliates or subsidiaries. This is an independent and unofficial software. Use at your own risk.

super-bot's People

Contributors

gfaraj 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  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

super-bot's Issues

Add ability to schedule recurring reminders

Add ability to schedule recurring reminders to the reminders plugin.

This would probably be best implemented in a separate command like:

!remind

Example:

!remind 1w 1M Pay electric bill

This means: remind me to Pay electric bill in 1 week, and repeat every 1 month.

WhatsClient bug

i can't start the client for whatsapp because this give for me this following output:

Starting SuperBot for Whatsapp...
Loading WAPI...
Checking Whatsapp Web API...
(node:11348) UnhandledPromiseRejectionWarning: Error: Evaluation failed: TypeError: window.WAPI.isReady is not a function
at puppeteer_evaluation_script:2:33
at ExecutionContext._evaluateInternal (C:\Users\subze\OneDrive\Área de Trabalho\super-bot-master\node_modules\puppeteer\lib\ExecutionContext.js:122:13)
at processTicksAndRejections (internal/process/task_queues.js:93:5)
at async ExecutionContext.evaluate (C:\Users\subze\OneDrive\Área de Trabalho\super-bot-master\node_modules\puppeteer\lib\ExecutionContext.js:48:12)
at async WhatsappClient.start (C:\Users\subze\OneDrive\Área de Trabalho\super-bot-master\clients\whatsapp\src\WhatsappClient.js:109:16)
at async main (C:\Users\subze\OneDrive\Área de Trabalho\super-bot-master\clients\whatsapp\src\app.js:8:5)
-- ASYNC --
at ExecutionContext. (C:\Users\subze\OneDrive\Área de Trabalho\super-bot-master\node_modules\puppeteer\lib\helper.js:111:15)
at DOMWorld.evaluate (C:\Users\subze\OneDrive\Área de Trabalho\super-bot-master\node_modules\puppeteer\lib\DOMWorld.js:112:20)
at processTicksAndRejections (internal/process/task_queues.js:93:5)
-- ASYNC --
at Frame. (C:\Users\subze\OneDrive\Área de Trabalho\super-bot-master\node_modules\puppeteer\lib\helper.js:111:15)
at Page.evaluate (C:\Users\subze\OneDrive\Área de Trabalho\super-bot-master\node_modules\puppeteer\lib\Page.js:833:43)
at Page. (C:\Users\subze\OneDrive\Área de Trabalho\super-bot-master\node_modules\puppeteer\lib\helper.js:112:23)
at WhatsappClient.start (C:\Users\subze\OneDrive\Área de Trabalho\super-bot-master\clients\whatsapp\src\WhatsappClient.js:109:32)
at processTicksAndRejections (internal/process/task_queues.js:93:5)
at async main (C:\Users\subze\OneDrive\Área de Trabalho\super-bot-master\clients\whatsapp\src\app.js:8:5)
(node:11348) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:11348) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

is it possible to correct? i was making AI modules,

Add a Trivia plugin

As a user, I would like to play a trivia game with my friends using this bot.

The following should start a trivia game for the "coding" category:

!trivia coding

When a trivia game is started, any subsequent command in that "chat" should be routed to the trivia plugin and handled as an answer.

Erro at start

When try start command "npm run start" get error

C:\super-bot-master\src\super-bot\SuperBot.js:47
commands = {};
^

SyntaxError: Unexpected token =
at new Script (vm.js:83:7)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:789:10)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! [email protected] start: node .
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] start script.

Add ability to funnel the response of one command to another

I would like to pass the output of one command as the input of another command effortlessly.

One way that this can be implemented is similar to pipes in a command-line:

!translate es Hello, how are you? | translate en

The above example executes the first command - which translates "Hello, how are you?" into Spanish - and then pipes the response - "¿Hola, como estas?" to the next command in the pipeline. This would end up calling "translate en ¿Hola, como estas?" which would re-translate that to English.

You should be able to have more than one pipe in a single line.

If there are better ways of achieving something similar, we can discuss them as well.

Add docker support

I would like to be able to run the bot service as a docker container.

Caption in attachment

Hello, i would like to set an caption in the attachment object for images.
Something like this:

    bot.respond({ attachment: {
        data: `data:image/jpeg;base64,${albumImage}`,
        mimetype: 'image/jpeg',
        //caption:`Album Image` <--------------
    }});

Add a reminders plugin

A plugin for adding reminders would be good.

It should work by giving the following command:

!remindme 1w Pay the electric bill

It will allow the following time format:

1y2M3w4h10m

For specifying years, months, weeks, hours, and minutes in the future.

Problem in start

Hello i try to start but and dont know where i have to go to bot can read messages i run npm run start and it reply :

Starting SuperBot...
Loading plugins from path: C:\Users\subze\OneDrive\Área de Trabalho\super-bot-master\src\plugins
Loading plugin: admin.js...
Initializing plugin: admin.js...
Done plugin: admin.js...
Loading plugin: core.js...
Initializing plugin: core.js...
Done plugin: core.js...
Loading plugin: echo.js...
Initializing plugin: echo.js...
Done plugin: echo.js...
Loading plugin: evaluate.js...
Initializing plugin: evaluate.js...
Done plugin: evaluate.js...
Loading plugin: google.js...
Initializing plugin: google.js...
Done plugin: google.js...
Loading plugin: livescore.js...
Initializing plugin: livescore.js...
Done plugin: livescore.js...
Loading plugin: natural.js...
Initializing plugin: natural.js...
Done plugin: natural.js...
Loading plugin: poll.js...
Initializing plugin: poll.js...
Done plugin: poll.js...
Loading plugin: record.js...
Initializing plugin: record.js...
Done plugin: record.js...
Loading plugin: reminders.js...
Initializing plugin: reminders.js...
Done plugin: reminders.js...
Loading plugin: remove_bg.js...
Initializing plugin: remove_bg.js...
Done plugin: remove_bg.js...
Loading plugin: sticker.js...
Initializing plugin: sticker.js...
Done plugin: sticker.js...
Loading plugin: tell.js...
Initializing plugin: tell.js...
Done plugin: tell.js...
Loading plugin: translate.js...
Initializing plugin: translate.js...
Done plugin: translate.js...
Listening on port 3000

where i have to go to login with whatsapp?? thanks for help, and good project

Error sending sticker.

Describe the bug
Error sending sticker (Store.CryptoLib.encryptE2EMedia is not a function)

To Reproduce
Steps to reproduce the behavior:
Sending a sticker.

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.