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 🙏

© 2026 – Pkg Stats / Ryan Hefner

@pitolabs/agent-whatsapp

v0.1.1

Published

A WhatsApp number as a Mastra agent channel: Baileys linked device, pairing page, one turn per burst of messages, voice notes to text, WhatsApp-flavoured Markdown

Readme

👋 Welcome to agent-whatsapp

Put your Mastra agent on a WhatsApp number. The number is a linked device (like WhatsApp Web), paired from a page in your app; people write to it, send voice notes and photos, and the agent answers in WhatsApp's own formatting. "2 latas de tinta branca e um rolo", typed in three messages and a voice note, reaches the agent as one turn.

Built for Mastra Channels on the Chat SDK and the chat-adapter-baileys adapter. The burst queue (createBurstQueue) has no framework dependency.

✨ What you get

  • 📱 A linked device per number: linkedDevice({ authDir, userName, logPrefix }) gives the Chat SDK adapter, its link state and the bot's own JID and LID; the session lives in a folder you choose.
  • 🔗 A pairing page: pairingRoutes(path, title, phone, link, middleware) shows the QR, or a code for pairing by phone number, behind your own login check; the QR and the code never reach the logs.
  • 🧺 One turn per burst: messages from one sender are batched (2 s of quiet, 8 s at most, closed early when someone else writes) and run one at a time per conversation.
  • 🎙️ Voice notes as text: each audio goes to an OpenAI-compatible /audio/transcriptions endpoint and becomes [Áudio transcrito] … in the message the agent reads.
  • 🚪 Admission in your hands: an Admit function decides per raw message and stamps the request context; samePhone compares Brazilian numbers with or without the ninth digit.
  • ✍️ WhatsApp formatting: WhatsAppConverter turns the model's Markdown into WhatsApp marks (tables become list lines), and WHATSAPP_FORMAT tells the model what WhatsApp can show.
  • 👥 Groups by @ only: mentionsBot reads native mentions (contextInfo.mentionedJid), which the Chat SDK alone never sees.

🪶 Light, cheap, yours

  • 🪶 Two runtime dependencies (pino, qrcode); Mastra, Chat SDK, Baileys and the adapter are peers you already have. One entry point, plain ES modules.
  • 🔐 Private by default: logs carry message ids, lengths and status codes, never message text, transcripts, QR codes or pairing codes. Speech-to-text goes only to the server you configure.
  • 🧰 One process: the device connects from your app; no extra service besides your speech-to-text server.

🚀 Quick start

bun add @pitolabs/agent-whatsapp      # or: npm install @pitolabs/agent-whatsapp
import { Agent } from "@mastra/core/agent";
import { ApprovalGate } from "@pitolabs/agent-docs/mastra";
import { linkedDevice, samePhone, senderPhone, sttConfig, WHATSAPP_FORMAT, whatsappHandler } from "@pitolabs/agent-whatsapp";

const device = await linkedDevice({ authDir: "./whatsapp-auth", userName: "Clerk", logPrefix: "clerk" });
const staff = ["15550100100"];

const handler = whatsappHandler({
	log: "clerk",
	gate: new ApprovalGate(),
	stt: sttConfig({ url: process.env.STT_URL, token: process.env.STT_TOKEN }),
	admit: (raw) => {
		const phone = senderPhone(raw);
		const person = phone && staff.find((p) => samePhone(p, phone));
		if (!person || raw.key.remoteJid?.endsWith("@g.us")) return { admit: false, reason: "not staff" };
		return { admit: true, sender: person, stamp: (ctx) => ctx.set("clerkPerson", person) };
	},
});

export const clerk = new Agent({
	id: "clerk",
	name: "Clerk",
	model: "openai/gpt-4o-mini",
	instructions: `You help the shop's staff.\n\n${WHATSAPP_FORMAT}`,
	channels: {
		adapters: { whatsapp: { adapter: device.adapter, textFormat: "markdown", toolDisplay: "hidden" } },
		handlers: { onDirectMessage: handler, onMention: handler, onSubscribedMessage: handler },
		userName: "Clerk",
		// The pairing page learns the link state from this logger; it also logs a status heartbeat.
		chatOptions: { logger: device.link.chatLogger("clerk-chat") },
	},
});

Your app then initializes the channels and calls device.connect(), and mounts pairingRoutes behind its login. The guide walks through it.

📚 Learn more

|Page|Answers| |---|---| |📘 Guide|How do I wire it in, pair the number, and run speech-to-text?| |📖 Reference|What does each export accept and do?| |🤝 Contributing|Setup, hooks, tests, releasing.|

🇧🇷 Language

The texts people see (the pairing page, the transcript markers, WHATSAPP_FORMAT) are in Brazilian Portuguese: the package comes from agents that answer in it.

💜 Who made it

Pito Labs, from the WhatsApp agents we run. MIT licensed; issues and pull requests welcome.