chatbox-utility
v1.0.6
Published
A package to handle chat functionalities and file downloads for facebook chatbot messenger!
Downloads
646
Readme
# chatbox-utility
A package that provides chat utilities, text formatting styles, and file downloading features.
## Installation
Install the package using npm:
```bash
npm install chatbox-utility
Usage
Importing the Package
After installation, you can import the package in your code:
const { OnChat, font } = require('chatbox-utility');
Font Styles
You can use the font
object to apply different text styles:
console.log(font.bold("Bold text"));
console.log(font.italic("Italic text"));
console.log(font.underline("Underlined"));
OnChat Class
Creating an Instance of OnChat
You need to pass your apiObject
and eventObject
to create an instance of OnChat
:
// can be embeded in auto, mirai, goatbot cmds
module.exports["run"] = async ({ api, event }) => {
const box = new OnChat(api, event);
box.reply("hello world", event.threadID);
}
Methods of OnChat
Here’s a list of available methods:
log(text)
: Logs a message with a rainbow effect.box.log("Hello, World!");
profile(link, caption, date)
: Changes the profile picture./* this will change your bot fb profile picture*/ box.profile('https://example.com/image.jpg', 'Profile Updated');
post(message)
: Creates a post./* this will post a content in your fb bot*/ box.post("Your post content here."); /* to attach image in your post*/ box.post({ body: "my caption", attachment: await box.stream("your image url, you can also change this into array to attach multiple url image all at once") })
react(emoji, messageID, isReaction)
: Reacts to a specific message with an emoji.box.react('👍', event.messageID);
reply(message, threadID)
: Replies to a message in a thread.box.reply("Hello!", event.threadID);
nickname(name, userID)
: Changes the nickname in a group chat.box.nickname("New Nickname", '123456789'); /* this doesnt work sometimes on other gc idk the reason */
userInfo(userID)
: Retrieves information about a user.box.userInfo('123456789').then(info => box.reply(JSON.stringify(info)));
arraybuffer(url, extension)
: Downloads a file as an array buffer.box.arraybuffer('https://example.com/image.png', 'png').then(buffer => { box.reply(buffer) /* converted to base64 */ });
-stream(url)
: Streams the file url directly without needing to download.
box.stream('https://example.com/image.png').then(stream => {
box.reply(stream) /* converted to stream response */
});
cover(link)
: Changes the cover photo of the chatbot.box.cover('https://example.com/cover.png');
API Reference
font Styles
bold
: Makes text bold.italic
: Makes text italicized.underline
: Underlines the text.monospace
: Renders text in monospace font.strike
: Strikes through the text.roman
: turns the text to roman style.bubble
: turns the text to bubble style.squarebox
: turns the text to squarebox style.thin
: makes the text thin.origin
: turns any text with font style back to original.
OnChat Methods
| Method | Description |
|---------------------|-------------------------------------------------------------------|
| log(text)
| Logs a rainbow-style message to the console. |
| error(text)
| Logs an error message in red. |
| profile(link)
| Changes the bot's profile picture. |
| post(message)
| Posts a content. |
| react(emoji)
| Reacts to a specific message. |
| nickname(name)
| Changes the nickname of the bot in a chat. |
| userInfo(id)
| Retrieves user information by ID. |
| reply(message)
| Sends a reply message in a thread. |
| arraybuffer(url)
| Downloads a file from the provided URL as an array buffer. |
| stream(url)
| stream the file url directly without downloading.
| cover(link)
| Changes the cover photo of the chatbot. |
Error Handling
If any method throws an error due to missing arguments, a relevant error message will be displayed.
For example:
box.reply(); // Throws an error due to "Missing parameters or message to reply!" you will need handle it manually using try catch
Contributing
Feel free to open issues or submit pull requests to improve this package.
License
This package is licensed under the MIT License.