@im-dims/utils
v0.2.7
Published
function for kasumi bot
Readme
SIMPLICITY WHATSAPP BOT
A clean and efficient WhatsApp bot library powered by Baileys. Built to simplify bot development, making it easier to build, adapt, and run your WhatsApp automation with minimal effort.
Example
To see an example in action, visit the kasumi-bot repository.
Connection
Simple way to make connection
const { Connection, Functions: Func, Config: env } = new (require('@im-dims/utils'))
const conn = new Connection({
directory: 'plugins',
session: 'session',
online: true,
bypass_ephemeral: true,
version: [2, 3000, 1022545672] // To see the latest version : https://wppconnect.io/whatsapp-versions/
}, {
shouldIgnoreJid: jid => {
return /(newsletter|bot)/.test(jid)
}
})Handling Events
There are several events that can be used are as follows :
conn.once('slips', ex => console.log(ex))
conn.once('prepare', () => console.log)
conn.once('poll', ctx => console.log(ctx))
conn.ev('message.delete', ctx => console.log(ctx))
conn.ev('presence.update', ctx => console.log(ctx))
conn.ev('group-participants.update', ctx => console.log(ctx))
conn.ev('group.detect', ctx => console.log(ctx))
conn.ev('call', ctx => console.log(ctx))
conn.ev('message.reaction', ctx => console.log(ctx))
conn.ev('groups.update', ctx => console.log(ctx))
conn.ev('chats.update', ctx => console.log(ctx))
conn.ev('contacts.update', ctx => console.log(ctx))
conn.ev('contacts.upsert', ctx => console.log(ctx))
conn.ev('message-receipt.update', ctx => console.log(ctx))Message Metadata
WebMessageInfo {
messageStubParameters: [],
labels: [],
userReceipt: [],
reactions: [],
pollUpdates: [],
eventResponses: [],
statusMentions: [],
messageAddOns: [],
statusMentionSources: [],
supportAiCitations: [],
key: MessageKey {
remoteJid: '[email protected]',
fromMe: false,
id: '4F38BA4A38B5BBFCAF62447AE7C2FE77',
participant: '[email protected]'
},
message: { conversation: '=> m' },
messageTimestamp: Long { low: 1749750736, high: 0, unsigned: true },
broadcast: false,
pushName: 'Xyuzu Is Here!',
_text: '=> m'
}Messaging Function
// declaration variable sock
const slips = conn.sock
// send a text message (auto tagged)
slips.reply(m.chat, 'Test!', m)
// send a react message
slips.sendReact(m.chat, '💀', m.key)
// send a text message with progress bar
slips.sendProgress(m.chat, 'Test!', m)
// send a ptv message from path, url, or buffer (video duration 10s)
slips.sendPtv(m.chat, './src/video/aiskurimu.mp4')
// send a text message with custom thumbnail
slips.sendMessageModify(m.chat, 'Test!', m, {
title: '© kasumi-bot',
largeThumb: true,
ads: false,
/* can buffer or url */
thumbnail: 'https://qu.ax/ABlXC.jpg',
link: 'https://whatsapp.com/channel/0029VaDs0ba1SWtAQnMvZb0U'
})
// send a file from path, url, or buffer (auto extension)
slips.sendFile(m.chat, 'https://qu.ax/55', 'image.jpg', 'Test!', m)
// send a document from path, url, or buffer (auto extension)
slips.sendFile(m.chat, 'https://qu.ax/ABlXC.jpg', 'image.jpg', 'Test!', m, {
document: true
})
// send a voicenote from path, url, or buffer
slips.sendFile(m.chat, './src/audio/ah.mp3', '', '', m, {
ptt: true
})
// send a audio from path, url, or buffer with thumbnail in audio tag
slips.sendFile(m.chat, './src/audio/ah.mp3', '', '', m, {
APIC: < Buffer >
})
// send a sticker message from url or buffer
slips.sendSticker(m.chat, 'https://qu.ax/ABlXC.jpg', m, {
packname: 'Sticker by',
author: '© kasumi-bot'
})
// send polling message
slips.sendPoll(m.chat, 'Do you like this library ?', {
options: ['Yes', 'No'],
multiselect: false
})
// send contact message
slips.sendContact(m.chat, [{
name: 'Dimas Triyatno',
number: '6282128385538',
about: 'Owner & Creator'
}], m, {
org: 'Kasumi Support',
website: 'https://api.ssateam.my.id',
email: '[email protected]'
})
// forward message
slips.copyNForward(m.chat, m)
// send interactive button message (your own risk)
var buttons = [{
name: 'quick_reply',
buttonParamsJson: JSON.stringify({
display_text: 'Owner',
id: '.owner'
}),
}, {
name: 'cta_url',
buttonParamsJson: JSON.stringify({
display_text: 'Rest API',
url: 'https://api.ssateam.my.id',
merchant_url: 'https://api.ssateam.my.id'
})
}, {
name: 'cta_copy',
buttonParamsJson: JSON.stringify({
display_text: 'Copy',
copy_code: '123456'
})
}, {
name: 'cta_call',
buttonParamsJson: JSON.stringify({
display_text: 'Call',
phone_number: '6282128385538'
})
}, {
name: 'single_select',
buttonParamsJson: JSON.stringify({
title: 'Tap!',
sections: [{
rows: [{
title: 'Owner',
description: 'X',
id: '.owner'
}, {
title: 'Runtime',
description: 'Y',
id: '.run'
}]
}]
})
}]
// button & list
slips.sendIAMessage(m.chat, buttons, m, {
header: '',
content: 'Hi!',
footer: '',
media: global.db.setting.cover // video or image link
})
// carousel message
const cards = [{
header: {
imageMessage: global.db.setting.cover,
hasMediaAttachment: true,
},
body: {
text: 'P'
},
nativeFlowMessage: {
buttons: [{
name: 'cta_url',
buttonParamsJson: JSON.stringify({
display_text: 'Contact Owner',
url: 'https://api.ssateam.my.id',
webview_presentation: null
})
}]
}
}, {
header: {
imageMessage: global.db.setting.cover,
hasMediaAttachment: true,
},
body: {
text: 'P'
},
nativeFlowMessage: {
buttons: [{
name: 'cta_url',
buttonParamsJson: JSON.stringify({
display_text: 'Contact Owner',
url: 'https://api.ssateam.my.id',
webview_presentation: null
})
}]
}
}]
slips.sendCarousel(m.chat, cards, m, {
content: 'Hi!'
})
// send message with "AI" label (only work if your bot using WhatsApp Business)
slips.replyAI(m.chat, 'Hi!', m)Big Thanks To
Special thanks to Neoxr and Nando for their inspiring codebases that helped shape this project.
