view360_chat 1.0.12
view360_chat: ^1.0.12 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 a responsive customer interaction experience.
๐งฉ Features #
- ๐ Real-time Socket Connection โ Connect instantly to View360โs chat server.
- ๐ฌ Send Messages โ Deliver customer messages with optional file attachments.
- ๐ฅ Retrieve Chat History โ Fetch all previous messages in a conversation.
- ๐งพ Customer Information Support โ Easily handle customer name, email, and phone number.
- โ๏ธ Simple Setup โ Quick and easy configuration with your base URL and App ID.
๐ ๏ธ Connecting the Socket #
First, you need to connect the socket. This is used to receive messages from the agent side.
You can do this during the chat registration page, which helps you obtain socketManager.socket.id that is required for sending messages using sendChatMessage() for the first time.
You also need to provide the baseUrl.
In the onMessage callback:
contentrefers to the message sent by the agent,createdAtindicates when the message was created,senderTypealways refers to the agent,filePathscontains any files sent by the agent.
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');
},
);
โ๏ธ Sending Messages #
The sendChatMessage function is used to send messages to the agent.
This is the same function used during the initial chat registration process.
During chat registration:
- You do not need to pass
filePathandcustomerId. - Make sure that the
chatIdis unique. This samechatIdmust be used when sending messages to the agent afterward. - When getting the
socketId, always fetch it directly fromsocketManager.socket.id, because there is a chance that thesocketIdcan change while chatting.
When sending a message from the chat list:
- Make sure to provide the
customerId.
After registering:
- If an agent is available, you will receive the
customerIdand thestatuswill betrue. - If no agent is available, the
successstatus will still betrue, andisInQueuewill betrue. You can still access thecustomerIdin this case.
After sending a message to the agent:
- You will get a
successresponse if the message was sent successfully.
import 'package:view360_chat/view360_chat.dart';
final chatService = ChatService(
baseUrl: 'yourdomain.com',
appId: 'your-app-id',
);
final response = await chatService.sendChatMessage(
filePath: [], // optional
customerId, // optional
chatContent: 'Hello from View360!',
chatId: 'abc123', // make it unique
socketId: socketManager.socket.id!,
customerName: 'John Doe',
customerEmail: 'john@example.com',
customerPhone: '1234567890',
);
๐ Fetching Message History #
The fetchMessages function is used to fetch the current list of chat messages.
You need to provide the customerId to retrieve the conversation history.
import 'package:view360_chat/view360_chat.dart';
final history = await chatService.fetchMessages(customerId: '1234');
if (history.success) {
print('๐ฌ Chat History: ${history.messages}');
} else {
print('โ Error: ${history.error}');
}