megan-chat-sdk
v1.0.3
Published
Official SDK for Megan Chat API — Build WhatsApp-like apps in minutes
Maintainers
Readme
Megan Chat SDK
The official JavaScript SDK for Megan Chat API — build real-time chat applications in minutes. Messaging, voice/video calls, stories, groups, GIFs, stickers, and more.
🚀 Quick Start
npm install megan-chat-sdkimport MeganChat from "megan-chat-sdk";
const chat = new MeganChat({
apiKey: "megan_chat_xxxx", // Get your free API key at chat.megan.qzz.io
});
// Register & login
await chat.register({
email: "[email protected]",
password: "securePassword123",
username: "alice",
});
// Send a message
chat.sendMessage("general", "Hello world! 👋");
// Listen for messages
chat.on("message", (msg) => {
console.log(`${msg.user}: ${msg.text}`);
});📦 Features
Category Features 💬 Messaging Send, edit, delete, forward, reply, @mentions, drafts, search 📹 Voice & Video 1-on-1 calls, group calls (50+), screen sharing, mute 👥 Groups Create rooms, mute, disappearing messages, invites 📱 Stories Post text/image stories, 24hr expiry, views 🎯 Reactions 👍 ❤️ 😂 😮 😢 😡 on any message 🔍 Search Full-text message search, user search by name/phone/ID 📍 Location Share live location with map links 📊 Polls Create polls, vote, real-time results 🎨 Media Images, video, audio, GIFs (Giphy/Tenor), stickers 🔒 Privacy Last seen, online status, read receipts, profile photo 📱 Multi-device Link phone + laptop + tablet, messages sync 🌙 More Block users, scheduled messages, chat backup, webhooks
📖 API Reference
Authentication
// Email registration
const { user, token } = await chat.register({
email: "[email protected]",
password: "securePass123",
username: "cooluser",
displayName: "Cool User", // optional
});
// Email login
const { user } = await chat.login({
email: "[email protected]",
password: "securePass123",
});
// Phone registration (SMS verification)
await chat.phoneRegister({
phone: "+254712345678",
username: "kenyanuser",
});
// Verify phone code
await chat.verifyCode("+254712345678", "482917");
// Phone login
await chat.phoneLogin("+254712345678");
// Reset password
await chat.resetPassword("[email protected]");
// Delete account permanently
await chat.deleteAccount();Messaging
// Send a message
chat.sendMessage("room-123", "Hello everyone!");
// Send a sticker
chat.sendSticker("room-123", "thumbsup", "👍");
// Send typing indicator
chat.sendTyping(true); // User is typing...
chat.sendTyping(false); // Stopped typing
// Edit a message
await chat.editMessage("msg-123", "Updated text");
// Delete a message
await chat.deleteMessage("msg-123");
// Forward a message
await chat.forwardMessage("msg-123", "room-a", "room-b");
// Get message history (with pagination)
const { messages, hasMore } = await chat.getMessages("room-123");
const older = await chat.getMessages("room-123", messages[0].timestamp);
// Search messages
const results = await chat.searchMessages("hello");
// Star/bookmark a message
await chat.starMessage("msg-123");
const starred = await chat.getStarredMessages();
// Draft messages
await chat.saveDraft("room-123", "Draft text...");
const drafts = await chat.getDrafts();
// Schedule a message
await chat.scheduleMessage("room-123", "Happy birthday!", Date.now() + 86400000);
// Send @mentions
chat.sendMessage("room-123", "Hey @bob check this out!");Voice & Video Calls
// Start a video call
const call = await chat.startCall("user456", { type: "video" });
// Show local video
document.getElementById("localVideo").srcObject = call.localStream;
// Listen for remote stream
chat.on("remoteStream", (stream) => {
document.getElementById("remoteVideo").srcObject = stream;
});
// End the call
await call.end();
// Listen for incoming calls
chat.on("incomingCall", async (call) => {
const accept = confirm(`Incoming ${call.callType} call from ${call.from}`);
if (accept) {
await chat.acceptCall(call.callId);
} else {
await chat.endCall(call.callId);
}
});
// Mute/unmute
await chat.muteCall(callId, true); // mute
await chat.muteCall(callId, false); // unmuteFriends & Social
// Get friends list
const { friends } = await chat.getFriends();
// Send friend request
await chat.sendFriendRequest("bob");
// Accept friend request
await chat.acceptFriend("request-123");
// Search users
const { users } = await chat.searchUsers("alice");
// Search by phone number
const { user } = await chat.searchByPhone("+254712345678");
// Search by Megan ID
const { user } = await chat.searchByMeganId("MG-254-712345-a3f2");
// Sync phone contacts to find friends
const { contacts } = await chat.syncContacts(["+254712345678", "+254723456789"]);
// Block a user
await chat.blockUser("user123");
// Update bio
await chat.updateBio("Software developer | Coffee lover ☕");Groups & Rooms
// Create a group
const { room } = await chat.createRoom("My Team", "group", ["user1", "user2"]);
// Get all your rooms
const { rooms } = await chat.getRooms();
// Mute a room (1 hour, 8 hours, or forever)
await chat.muteRoom("room-123", 3600000); // 1 hour
await chat.muteRoom("room-123", 0); // unmute
// Get muted rooms
const { muted } = await chat.getMutedRooms();Stories / Status
// Post a text story
await chat.postStory({
type: "text",
content: "Having a great day! ☀️",
bgColor: "#6C63FF",
});
// Post an image story
await chat.postStory({
type: "image",
content: "data:image/png;base64,...",
caption: "Sunset at the beach 🌅",
});
// Get friends' stories
const { stories } = await chat.getStories();
// Mark a story as viewed
await chat.viewStory("story-123");Reactions
// React to a message
await chat.react("msg-123", "👍"); // thumbs up
await chat.react("msg-123", "❤️"); // heart
await chat.react("msg-123", "😂"); // laugh
await chat.react("msg-123", "😮"); // wow
await chat.react("msg-123", "😢"); // sad
await chat.react("msg-123", "😡"); // angryMedia & GIFs
// Send an image/video/file
const fileInput = document.getElementById("fileInput");
const file = fileInput.files[0];
await chat.sendMedia("room-123", file, "image");
// Search GIFs
const gifs = await chat.searchGIFs("funny cats", 20);
// [{ id, url, preview, title }, ...]
// Get stickers
const stickers = await chat.getStickers();
// [{ id, url, pack }, ...]Polls
// Create a poll
const { pollId } = await chat.createPoll("room-123", "Best programming language?", [
"JavaScript",
"TypeScript",
"Python",
"Go",
]);
// Vote on a poll
await chat.votePoll(pollId, 0); // Vote for first option
// Listen for poll updates
chat.on("pollUpdated", (data) => {
console.log("Poll results updated:", data.results);
});Location Sharing
// Share your location
await chat.shareLocation("room-123", -1.2921, 36.8219, "Nairobi, Kenya");
// Returns mapUrl: https://maps.google.com/?q=-1.2921,36.8219
// Listen for locations
chat.on("location", (data) => {
console.log(`${data.userId} shared: ${data.mapUrl}`);
});Privacy Settings
// Configure privacy
await chat.setPrivacy({
lastSeen: "everyone", // everyone | friends | nobody
onlineStatus: "friends", // everyone | friends | nobody
profilePhoto: "everyone", // everyone | friends | nobody
readReceipts: true, // true | false
});
// Get current privacy settings
const { settings } = await chat.getPrivacy();Multi-Device Linking
// Generate pairing code on primary device
const { pairCode } = await chat.generatePairCode();
// Shows: "482917" — enter this on your new device
// Link new device using the code
await chat.linkDevice("482917", "My Laptop", "desktop");
// View linked devices
const { devices } = await chat.getDevices();
// Unlink a device
await chat.unlinkDevice("device-123");Events (Real-time Listeners)
// Messages
chat.on("message", (msg) => console.log(msg.user, msg.text));
chat.on("messageEdited", (data) => console.log("Edited:", data));
chat.on("messageDeleted", (data) => console.log("Deleted:", data.messageId));
// Typing & Presence
chat.on("typing", (data) => console.log(data.user, "is typing..."));
chat.on("presence", (users) => console.log("Online:", users));
chat.on("userJoined", (data) => console.log(data.user, "joined"));
chat.on("userLeft", (data) => console.log(data.user, "left"));
// Calls
chat.on("incomingCall", (call) => handleIncomingCall(call));
chat.on("callAccepted", (data) => console.log("Call accepted!"));
chat.on("callEnded", (data) => console.log("Call ended:", data.reason));
chat.on("remoteStream", (stream) => showVideo(stream));
chat.on("groupCallInvite", (data) => console.log("Group call from", data.creator));
// Content
chat.on("reaction", (data) => console.log(data.userId, "reacted", data.reaction));
chat.on("readReceipt", (data) => console.log(data.userId, "read at", data.timestamp));
chat.on("mediaMessage", (data) => console.log("Media:", data.mediaType));
chat.on("sticker", (data) => console.log("Sticker:", data.stickerId));
chat.on("location", (data) => console.log("Location:", data.mapUrl));
chat.on("pollCreated", (data) => console.log("New poll:", data.question));
chat.on("pollUpdated", (data) => console.log("Poll results:", data.results));
chat.on("mention", (data) => console.log("You were mentioned!"));Data & Backup
// Export chat data (GDPR compliant)
const backup = await chat.exportChat("json"); // or "csv"
console.log(backup.messages, backup.friends);
// Configure notification preferences
await chat.setNotificationPrefs({
messageNotifications: true,
callNotifications: true,
mentionNotifications: true,
groupNotifications: false,
storyNotifications: false,
});
// Mark a room as unread
await chat.markUnread("room-123", true);🎯 Framework Integrations
React
import { useState, useEffect } from "react";
import MeganChat from "megan-chat-sdk";
const chat = new MeganChat({ apiKey: "megan_chat_xxxx" });
function ChatApp() {
const [messages, setMessages] = useState([]);
useEffect(() => {
chat.on("message", (msg) => setMessages((prev) => [...prev, msg]));
return () => chat.disconnect();
}, []);
const send = (text) => chat.sendMessage("general", text);
return (
<div>
{messages.map((msg) => (
<div key={msg.id}>{msg.user}: {msg.text}</div>
))}
<input onKeyDown={(e) => e.key === "Enter" && send(e.target.value)} />
</div>
);
}Vue
<template>
<div>
<div v-for="msg in messages" :key="msg.id">{{ msg.user }}: {{ msg.text }}</div>
<input @keydown.enter="send" v-model="text" />
</div>
</template>
<script setup>
import { ref, onMounted, onUnmounted } from "vue";
import MeganChat from "megan-chat-sdk";
const chat = new MeganChat({ apiKey: "megan_chat_xxxx" });
const messages = ref([]);
const text = ref("");
onMounted(() => {
chat.on("message", (msg) => messages.value.push(msg));
});
onUnmounted(() => chat.disconnect());
const send = () => {
chat.sendMessage("general", text.value);
text.value = "";
};
</script>📋 Requirements
· Browser: Chrome 60+, Firefox 55+, Safari 12+, Edge 79+ · Node.js: 16+ (for server-side usage) · API Key: Free from chat.megan.qzz.io
🔗 Links
· API Documentation · GitHub Repository · Megan APIs · Megan Coins
📄 License
MIT © 2026 Tracker Wanga • Falcon Tech
Built with ❤️ in Kenya 🇰🇪 EOF
Update package.json with better description
cat << 'EOF' > package.json { "name": "@megan/chat-sdk", "version": "1.0.0", "description": "Official JavaScript SDK for Megan Chat API — Build WhatsApp, Telegram, and Discord-like apps in minutes. Real-time messaging, voice/video calls, stories, groups, GIFs, stickers, and more.", "main": "dist/index.js", "types": "dist/index.d.ts", "scripts": { "build": "tsc", "dev": "tsc --watch", "prepublish": "tsc" }, "keywords": [ "chat", "messaging", "webrtc", "realtime", "websocket", "video-call", "voice-call", "stories", "whatsapp", "telegram", "discord", "megan", "falcon-tech" ], "author": "Tracker Wanga • Falcon Tech", "license": "MIT", "repository": { "type": "git", "url": "https://github.com/TrackerWanga/megan-chat-sdk" }, "homepage": "https://chat.megan.qzz.io", "devDependencies": { "typescript": "^5.0.0" } }
