Built-in Helpers
WhatsBotCord exports a global Helpers object containing robust utilities that simplify traversing deep Baileys structures, identifying media types, and debugging.
You can import them directly from the main package:
import { Helpers, MsgType, SenderType } from "whatsbotcord";Messages (Helpers.Msg)
Section titled “Messages (Helpers.Msg)”Functions tailored for manipulating and extracting data from incoming WhatsappMessage objects.
FullMsg_GetText(rawMsg)
Section titled “FullMsg_GetText(rawMsg)”Safely extracts the main text content, no matter if it’s a standard text message, an extended conversation, or an image/video with a caption! Returns null if the message has no text.
const text = Helpers.Msg.FullMsg_GetText(args.originalRawMsg);if (text) { console.log(`Received text: ${text}`);} else { console.log("Message does not contain any text.");}FullMsg_GetMsgType(rawMsg)
Section titled “FullMsg_GetMsgType(rawMsg)”Determines what kind of message arrived, mapping the raw structure into the clean MsgType enum (e.g. MsgType.Text, MsgType.Image).
const incomingMsgType = Helpers.Msg.FullMsg_GetMsgType(args.originalRawMsg);if (incomingMsgType === MsgType.Image) { await ctx.SendText("Nice image you sent!");}FullMsg_GetSenderType(rawMsg)
Section titled “FullMsg_GetSenderType(rawMsg)”Detects whether the message was sent inside an individual private chat (SenderType.Individual) or a group (SenderType.Group).
const senderType = Helpers.Msg.FullMsg_GetSenderType(args.originalRawMsg);if (senderType === SenderType.Group) { await ctx.SendText("This was sent from a group!");}FullMsg_GetQuotedMsg(rawMsg)
Section titled “FullMsg_GetQuotedMsg(rawMsg)”Returns the original message that the user replied (quoted) to.
const quotedMsg = Helpers.Msg.FullMsg_GetQuotedMsg(args.originalRawMsg);if (quotedMsg) { console.log("This message is replying to another message.");}FullMsg_GetQuotedMsgText(rawMsg)
Section titled “FullMsg_GetQuotedMsgText(rawMsg)”Extracts the text purely from the quoted message, ideal for !translate commands.
const repliedText = Helpers.Msg.FullMsg_GetQuotedMsgText(args.originalRawMsg);if (repliedText) { await ctx.SendText(`You quoted: ${repliedText}`);}WhatsApp Identifiers (Helpers.Whatsapp)
Section titled “WhatsApp Identifiers (Helpers.Whatsapp)”Functions for managing Identifiers (JIDs, LIDs, Mention strings). For a deeper explanation on these prefixes, see WhatsApp IDs.
GetWhatsInfoFromSenderMsg(rawMsg)
Section titled “GetWhatsInfoFromSenderMsg(rawMsg)”Fetches precise sender information (@g.us, @lid, @s.whatsapp.net) directly from the raw incoming Baileys payload.
const info = Helpers.Whatsapp.GetWhatsInfoFromSenderMsg(args.originalRawMsg);if (info) { console.log(`Sender ID: ${info.rawId}`);}GetWhatsInfoFromWhatsappID(idStr)
Section titled “GetWhatsInfoFromWhatsappID(idStr)”Parses standard raw suffix IDs.
const idStr = "1234567890@s.whatsapp.net";const parsedInfo = Helpers.Whatsapp.GetWhatsInfoFromWhatsappID(idStr);console.log(`Mention format: ${parsedInfo?.asMentionFormatted}`);Validations: IsPNId, IsLIDId, IsMentionString
Section titled “Validations: IsPNId, IsLIDId, IsMentionString”Boolean validators that quickly assert if a string meets the required ID properties.
const userMentionedStr = args.args[0]; // "@1234567890"
if (Helpers.Whatsapp.IsMentionString(userMentionedStr)) { const formattedInfo = Helpers.Whatsapp.GetWhatsInfoFromMentionStr(userMentionedStr); console.log("Raw ID output:", formattedInfo?.rawId); // Returns specific system ID}IdentifiersPostfixes
Section titled “IdentifiersPostfixes”Object holding constants dictating suffixes (Group_Suffix_ID, LID_Suffix_ID, PhoneNumber_Suffix_ID).
console.log(Helpers.Whatsapp.IdentifiersPostfixes.Group_Suffix_ID); // "@g.us"Debugging & Utilities
Section titled “Debugging & Utilities”Event Interception Dump
Section titled “Event Interception Dump”When developing new features (like interactive buttons or new media types), you may want to see the exact raw JSON structure that Baileys drops in. Calling Helpers.Debugging.StoreMsgInHistoryJson will dump the rawMsg payload into a .json file locally on your disk.
import { Debug_StoreWhatsMsgHistoryInJson } from "whatsbotcord/debugging";
bot.Use(async (bot, senderLID, senderPN, chatId, rawMsg, msgType, senderType, next) => { if (senderPN === "1234567890@s.whatsapp.net") { // Saves rawMsg safely without crashing your console! Debug_StoreWhatsMsgHistoryInJson(rawMsg); } await next();});Timeout/Aborts validation
Section titled “Timeout/Aborts validation”If you use Wait methods inside your core Chat Context waiting flows, an internal error will be thrown to interrupt execution if the user cancels or the prompt timeouts. You can safely verify if the error was a user interaction error or a system crash by using Helpers.ChatContext_IsWaitError.
try { await ctx.WaitText({ timeoutSeconds: 30 });} catch (error) { if (Helpers.ChatContext_IsWaitError(error)) { console.log("User didn't answer in 30 seconds or they cancelled the prompt."); } else { console.error("Critical server error occurred!"); }}