Messaging template for building whatsapp messages
npm install whatsapp-messagerEasily construct rich WhatsApp messages with bold, italic, strikethrough, monospace, and more! This library extends string-builder npm package with custom formatting options to simplify building professional, formatted WhatsApp messages programmatically.
---
Install the package using npm:
``bash`
npm install whatsapp-messager
`bash`
yarn add whatsapp-messager
---
- Rich Text Formatting: Bold, italic, strikethrough, and monospace text.
- Lists: Create ordered and unordered lists effortlessly.
- Template Placeholders: Easily replace placeholders with dynamic values.
- Quoting: Add blockquotes seamlessly.
- Chaining: Use method chaining for clean, readable code.
---
Here’s how you can get started with the WhatsApp Messager:
`typescript
import StringBuilder from 'whatsapp-messager';
const builder = new StringBuilder();
const message = builder
.bold("Welcome to WhatsApp!")
.italic("We hope you enjoy your stay.")
.quote("Here are some tips to get started:")
.unorderedList([
"Send messages to your friends.",
"Create group chats for family or work.",
"Use formatting for emphasis.",
])
.strikethrough("This is an outdated feature.")
.toString();
console.log(message);
`
``
Welcome to WhatsApp!
_We hope you enjoy your stay._
> Here are some tips to get started:
* Send messages to your friends.
* Create group chats for family or work.
* Use formatting for emphasis.
~This is an outdated feature.~
---
Example:
`typescript`
builder.append("This is some text.");
Example:
`typescript`
builder.appendLine("This is in a new line.");
Example:
`typescript`
builder.bold("This is bold text.");
Example:
`typescript`
builder.italic("This is italic text.");
Example:
`typescript`
builder.strikethrough("This is strikethrough text.");
Example:
`typescript`
builder.monospace("This is monospace text.");
Example:
`typescript`
builder.quote("This is a quote.");
Example:
`typescript`
builder.list(["First item", "Second item"], true); // Ordered
builder.list(["First item", "Second item"]); // Unordered
builder.list(["First item", "Second item"], false); // Unordered
Example:
`typescript`
const template = "Hello, {name}! Your order {orderNumber} is ready.";
const message = builder.toString({ name: "Jane", orderNumber: "12345" });
console.log(message);
Output:
``
Hello, Jane! Your order 12345 is ready.
Example:
`typescript`
builder.clear();
---
Use placeholders and escape {} if needed:
`typescript
const message = builder
.bold("Order Details:")
.append("Your order {reference} has been confirmed.")
.toString({ reference: 12345 });
console.log(message);
`
Output:
``
Order Details:
Your order 12345 has been confirmed.
---
`typescript
const message = builder
.bold("Order Details:")
.append("Your order \{12345\} has been confirmed.")
.toString();
console.log(message);
`
Output:
```
Order Details:
Your order {12345} has been confirmed.
---
1. Efficiency: Build complex messages programmatically.
2. Clean Code: Avoid messy string concatenation.
3. Dynamic Messages: Replace placeholders with dynamic values easily.
---
Feel free to submit issues or pull requests to help improve this library. Contributions are always welcome!
---
MIT