Welcome to the baileys-express-socketio-boilerplate repository, started on October 24, 2023, around 9 PM.
See similar project: WhatsApp-Web.js + Express + Socket.io + TypeScript Boilerplate
This repository is a project that combines the technologies of Baileys, Express, Socket.IO, and TypeScript. Baileys is used for interacting with WhatsApp Web, Express for server creation, Socket.IO for real-time communication, and TypeScript for type-based development.
-
Installation
git clone [email protected]:feri-irawan/baileys-express-socketio-boilerplate.git yarn
-
Running the Application
yarn dev
Make sure to configure the wa.config.ts
file correctly before running the application.
export default {
sessionName: 'my-session',
}
Create a command.js
file in the src/commands
folder and import it into src/commands/index.ts
, for example:
// src/commands/ping.ts
import { Command } from '@/lib/wa'
export const pingCommand: Command = {
name: 'ping',
description: 'Ping!',
handler: async ({ sock, message }) => {
await sock.sendMessage(message.key.remoteJid!, { text: 'Pong!' })
},
}
// src/commands/index.ts
import { Command } from '@/lib/wa'
import { pingCommand } from './ping'
export const commands: Command[] = [pingCommand]
Create a route.js
file in the src/routes
folder and import it into src/routes/index.ts
, for example:
// src/routes/ping.ts
import { Route } from '@/lib/server'
import { sock, status } from '@/lib/wa'
export const pingRoute: Route = {
path: '/ping',
method: 'GET',
handler: async (req, res) => {
if (status === 'open') {
const [receiver] = await sock.onWhatsApp('123456789') // 123456789 is the contact number
if (receiver.exists) {
await sock.sendMessage(receiver.jid, { text: 'Pong!' })
res.send('Pong!')
}
return
}
res.status(500).send('Server is not open')
},
}
// src/routes/index.ts
import { Route } from '@/lib/wa'
import { pingRoute } from './ping'
export const routes: Route[] = [pingRoute]
If you want to contribute to this project, please create a pull request and follow the contribution guidelines.
This project is licensed under the MIT license.
Thank you, and hope it is useful. Feel free to report issues or provide suggestions.