view360_chat 1.0.22
view360_chat: ^1.0.22 copied to clipboard
A Dart package for chat socket connection and messaging API for implimenting view360 chat feature.
๐ฆ view360_chat #
view360_chat
is a Flutter package designed for seamless integration of View360's real-time chat system into your applications.
It enables customer support chat functionality with features like live socket communication, file sharing, and message delivery tracking โ ideal for apps requiring responsive customer interaction.
๐งฉ Features #
- ๐ Real-time Socket Connection โ Instantly connect to View360โs chat server.
- ๐ฌ Send Messages โ Send messages with optional file attachments.
- ๐ฅ Retrieve Chat History โ Access the full conversation history.
- ๐งพ Customer Information Handling โ Easily pass customer name, email, and phone number.
- โ๏ธ Simple Setup โ Configure quickly with your base URL and App ID.
- ๐ฒ Push Notifications โ Receive notifications directly from View360.
๐ ๏ธ Connecting the Socket #
First, connect the socket to start receiving messages from the agent side.
Parameters: #
baseUrl
: View360 server URL.onMessage
: Callback triggered when a message is received from the agent.
Inside the onMessage
callback:
content
: Message from the agent.createdAt
: Timestamp of the message.senderType
: Sender info (always the agent).filePaths
: Any file attachments from the agent.
Example #
import 'package:view360_chat/view360_chat.dart';
final socketManager = SocketManager();
socketManager.connect(
baseUrl: 'https://yourdomain.com',
onMessage: ({
required content,
required createdAt,
required response,
required senderType,
filePaths,
}) {
print('๐ฉ New message: \$content');
},
);
โ๏ธ Create Chat Session #
The createChatSession
function is used to initiate a new chat session. During registration, you must provide either the customerPhone
or the customerEmail
. You may also provide both if available.
If no agent is currently available, the success
status will still be true
, and the isInQueue
flag will be set to true
.
Example #
import 'package:view360_chat/view360_chat.dart';
final chatService = ChatService(
baseUrl: 'https://yourdomain.com',
appId: 'your-app-id',
);
final response = await chatService.createChatSession(
chatContent: 'Hello from View360!',
customerName: 'John Doe',
customerEmail: 'john@example.com',
customerPhone: '1234567890',
);
if (response.success) {
print('โ
Chat session created successfully');
} else {
print('โ Failed to create chat session: ${response.error}');
}
โ๏ธ Sending Messages #
The sendChatMessage
function is used to send messages to the agent.
After sending a message:
- A
success
response indicates that the message was sent successfully.
import 'package:view360_chat/view360_chat.dart';
final response = await chatService.sendChatMessage(
filePath: [], // optional
chatContent: 'Hello from View360!',
);
๐ Supported File Attachments #
You can optionally attach files while sending a message. The following file types are supported:
- Images:
.jpg
,.jpeg
,.png
,.gif
- Documents:
.pdf
,.xlsx
,.csv
- Videos:
.mp4
โ Ensure that the file path(s) you pass in
filePath
end with one of the supported extensions.
๐ Fetching Message History #
The fetchMessages
function is used to retrieve the current list of chat messages.
Example #
import 'package:view360_chat/view360_chat.dart';
final history = await chatService.fetchMessages();
if (history.success) {
print('๐ฌ Chat History: \${history.messages}');
} else {
print('โ Error: \${history.error}');
}
๐ฒ Push Notifications on iOS #
To enable push notifications on iOS, the app must request notification permission from the user. Without this, Firebase Cloud Messaging (FCM) won't work. You need to call requestPermission()
to prompt the user for permission.
Steps to Request Notification Permission on iOS #
-
Add Permission Descriptions in
Info.plist
:
First, make sure to add the following entries in yourInfo.plist
file:<key>UIBackgroundModes</key> <array> <string>fetch</string> <string>remote-notification</string> </array> <key>UIUserTrackingUsageDescription</key> <string>Your description of why you need to track the user.</string>