A Flutter plugin for Twilio Conversations SDK which allows you to build engaging conversational messaging experiences for Android and iOS.
- Android
- iOS
- Generate Twilio Access Token(Only Android)
- Create new conversation
- Get list of conversations
- Fetch list of messages in the conversation
- Join an existing conversation
- Send Messages
- Listen to message update whenever new message is received
- Add participants in the conversation
- Remove participants from the conversation
- Get list of participants from the specific conversation
- Listen to access token expiration
- Update Read Messages
- Get Unread Message Count
Check out the example
final _twilioConversationSdkPlugin = TwilioConversationSdk();
// Use the Twilio helper libraries in your back end web services to create access tokens for both Android and iOS platform. However you can use this method to generate access token for Android.
final String? result = await _twilioConversationSdkPlugin.generateToken(accountSid:credentials['accountSid'],apiKey:credentials['apiKey'],apiSecret:credentials['apiSecret'],identity:credentials['identity'],serviceSid: credentials['serviceSid']);
/// Once you receive the access token from your back end web services, pass it to this method to authenticate the twilio user
final String result = await _twilioConversationSdkPlugin.initializeConversationClient(accessToken: accessToken);
final String? result = await _twilioConversationSdkPlugin.createConversation(conversationName:conversationName, identity: identity);
final List result = await _twilioConversationSdkPlugin.getConversations() ?? [];
final List result = await _twilioConversationSdkPlugin.getMessages(conversationId: conversationId) ?? [];
final String? result = await _twilioConversationSdkPlugin.joinConversation(conversationId:conversationId);
final String? result = await _twilioConversationSdkPlugin.sendMessage(message:enteredMessage,conversationId:conversationId);
final String? result = await _twilioConversationSdkPlugin.addParticipant(participantName:participantName,conversationId:conversationId);
final String? result = await _twilioConversationSdkPlugin.removeParticipant(participantName:participantName,conversationId:conversationId);
final List result = await _twilioConversationSdkPlugin.getParticipants(conversationId: conversationId) ?? [];
/// Use this method to listen to newly added messages in a conversation
_twilioConversationSdkPlugin.subscribeToMessageUpdate(conversationSid:widget.conversationSid);
_twilioConversationSdkPlugin.onMessageReceived.listen((event) {
});
/// Use this method to receive newly added messages in a conversation
_twilioConversationSdkPlugin.unSubscribeToMessageUpdate(conversationSid: widget.conversationSid);
_twilioConversationSdkPlugin.onTokenStatusChange.listen((tokenData) {
if (tokenData["statusCode"] == 401){
generateAndUpdateAccessToken()
}
});
/// Call this method if your access token is expired or is about to expire.
/// Regenerate the access token in your backend and use this method to update the token.
final Map? result = await _twilioConversationSdkPlugin.updateAccessToken(accessToken:accessToken);
/// Call this method whenever you want to receive unread count of conversation
final Map? result = await _twilioConversationSdkPlugin.getUnReadMsgCount(conversationId: widget.conversationSid);