Web Chat Widget
Msghub's web chat widget is a fully customizable chat interface that you can embed on your website. Visitors get instant answers from your AI chatbot, with seamless handoff to human agents when needed.
Web Chat Setup
Get the Embed Code
- Go to Settings → Channels → Web Chat
- Click Generate Embed Code
- Copy the code snippet
Embed on Your Website
Paste the code into your website's HTML, just before the closing </body> tag:
<script>
window.MsgHubConfig = {
apiKey: 'pk_live_...',
brandId: 'brand_abc123'
};
</script>
<script src="https://cdn.msghub.com/chat-widget.js"></script>
That's it! The chat widget will appear on your website.
Customization
Colors & Branding
- Go to Settings → Channels → Web Chat → Customization
- Configure:
- Primary Color — Button and header color
- Secondary Color — Accent color
- Text Color — Message text color
- Background Color — Chat background
- Logo — Your brand logo
- Brand Name — Display name in chat header
Position & Size
- Go to Settings → Channels → Web Chat → Customization
- Configure:
- Position — Bottom-right, bottom-left, or custom
- Width — Chat window width (300-500px)
- Height — Chat window height (400-800px)
- Offset — Distance from screen edge
Welcome Message
- Go to Settings → Channels → Web Chat → Customization
- Set:
- Welcome Title — "Chat with us"
- Welcome Message — "Hi! 👋 I'm your AI assistant. How can I help you today?"
- Placeholder Text — "Type your message..."
Buttons & CTAs
- Go to Settings → Channels → Web Chat → Customization
- Add buttons:
- Button Text — "Start Chat", "Ask a Question"
- Button Action — Open chat, trigger flow, external link
Chat Widget Features
Real-Time Messaging
Messages are delivered in real-time via Socket.io (no polling). Visitors see instant responses from your AI chatbot or human agents.
Typing Indicators
When an agent is typing, the visitor sees "Agent is typing...". This improves perceived response time.
Read Receipts
Visitors see when their messages are read by agents.
Conversation History
The chat widget remembers conversation history. If a visitor returns, they see their previous conversations.
Offline Mode
When no agents are available, the chat widget:
- Shows "We're offline" message
- Offers to collect their message
- Sends a notification to your team
- Responds when you're back online
AI Chatbot Integration
Setup
- Go to Settings → Channels → Web Chat
- Enable AI Chatbot
- Select your chatbot flow
- Click Save
Now, when a visitor opens the chat:
- Your AI chatbot greets them
- The chatbot answers their questions
- If the chatbot can't help, it escalates to a human agent
Example Conversation
Visitor: "What's your return policy?"
AI Chatbot: "We offer 30-day hassle-free returns! Would you like me to start a return for a recent order?"
Visitor: "Yes, I want to return my order"
AI Chatbot: "Great! I can help with that. What's your order number?"
Visitor: "ORD-4821"
AI Chatbot: "I found your order. It was placed on April 1st for $89.99. Would you like to proceed with the return?"
Visitor: "Yes"
AI Chatbot: "Perfect! I've initiated the return. You'll receive a prepaid shipping label via email. Just pack your item and drop it off at any shipping location. Is there anything else I can help with?"
Human Agent Handoff
When the AI chatbot can't resolve an issue, it escalates to a human agent.
Agent Inbox
- Go to Inbox
- You'll see web chat conversations
- Click on a conversation to open it
- You'll see:
- Full conversation history
- Visitor profile
- AI's summary of the issue
- Suggested responses
Responding as an Agent
- Click on the conversation
- Type your response
- Click Send
The visitor sees your response in real-time.
Agent Status
Set your availability status:
- Go Inbox → Status
- Choose:
- Online — Ready to chat
- Away — Temporarily unavailable
- Offline — Not available
When all agents are offline, the chat widget shows "We're offline" and collects messages.
Visitor Information
Capture Visitor Data
The chat widget automatically captures:
- Name — Visitor's name (optional)
- Email — Visitor's email (optional)
- Phone — Visitor's phone (optional)
- Company — Visitor's company (optional)
You can require certain fields:
- Go Settings → Channels → Web Chat → Customization
- Set required fields:
- Name — Required or optional
- Email — Required or optional
- Phone — Required or optional
Pre-Fill Visitor Info
If you know the visitor's information, pre-fill it:
<script>
window.MsgHubConfig = {
apiKey: 'pk_live_...',
brandId: 'brand_abc123',
visitor: {
name: 'Rahul',
email: 'rahul@example.com',
phone: '+919876543210',
company: 'Acme Corp'
}
};
</script>
Chat Widget Events
Trigger Flows from Chat
When a visitor sends a message, you can trigger a flow:
<script>
window.MsgHubConfig = {
apiKey: 'pk_live_...',
brandId: 'brand_abc123',
onMessage: function(message) {
// Trigger a flow when visitor sends a message
if (message.text.includes('refund')) {
// Trigger refund flow
window.MsgHub.triggerFlow('flow_refund', {
visitorId: message.visitorId,
message: message.text
});
}
}
};
</script>
Listen to Chat Events
<script>
window.MsgHubConfig = {
apiKey: 'pk_live_...',
brandId: 'brand_abc123',
onOpen: function() {
console.log('Chat opened');
},
onClose: function() {
console.log('Chat closed');
},
onMessage: function(message) {
console.log('Message received:', message);
},
onAgentAssigned: function(agent) {
console.log('Agent assigned:', agent.name);
}
};
</script>
Webhook Integration
Receive Chat Events
Configure a webhook to receive chat events:
curl -X POST \
https://your-msghub.com/api/v1/webhooks \
-H "X-API-Key: mk_live_..." \
-d '{
"event": "message.received",
"channel": "web_chat",
"url": "https://your-app.com/webhooks/chat"
}'
Msghub will POST chat events to your webhook:
{
"event": "message.received",
"messageId": "msg_xyz789",
"channel": "web_chat",
"visitorId": "visitor_123",
"visitor": {
"name": "Sarah",
"email": "sarah@example.com",
"phone": "+919876543210"
},
"message": {
"type": "text",
"text": "Hi, I have a question about your product"
},
"receivedAt": "2024-04-08T10:30:00Z"
}
Analytics
Chat Metrics
View chat analytics in the dashboard:
- Go Analytics → Web Chat
- See:
- Total Conversations — Number of chat sessions
- Average Response Time — Time to first response
- Visitor Satisfaction — Rating from visitors
- Chatbot Resolution Rate — % resolved by AI
- Agent Conversations — % escalated to agents
Conversation Quality
Rate conversations to improve your chatbot:
- Go Inbox → [Conversation]
- Click Rate Conversation
- Choose:
- Helpful — Chatbot/agent resolved the issue
- Partially Helpful — Partially resolved
- Not Helpful — Didn't resolve the issue
- Add comments (optional)
Best Practices
Welcome Message
- Be friendly — "Hi! 👋 How can we help?"
- Set expectations — "We typically reply in minutes"
- Offer options — "Ask a question or browse our FAQ"
- Mobile-friendly — Keep it short
Chatbot Responses
- Be helpful — Answer questions directly
- Be concise — Keep responses short
- Offer next steps — "Would you like to...?"
- Know when to escalate — "Let me connect you with an agent"
Agent Responses
- Respond quickly — Aim for under 2 minutes
- Be professional — Maintain brand voice
- Personalize — Use visitor's name
- Solve the problem — Don't just chat, help them
Timing
- Set business hours — Show when you're available
- Set auto-reply — "We'll respond during business hours"
- Monitor offline — Collect messages when offline
- Follow up — Respond to offline messages promptly
Troubleshooting
Chat widget not appearing
- Check embed code — Is it pasted correctly?
- Check API key — Is it valid?
- Check domain — Is your domain whitelisted?
- Check browser — Try a different browser
Slow message delivery
- Check internet — Is there a connectivity issue?
- Check chatbot — Is the AI chatbot enabled?
- Check load — Is Msghub overloaded?
Chatbot not responding
- Check chatbot — Is it enabled in Settings?
- Check flow — Is the flow configured correctly?
- Check knowledge base — Does it have answers?