twilio_chat_conversation 1.0.4 copy "twilio_chat_conversation: ^1.0.4" to clipboard
twilio_chat_conversation: ^1.0.4 copied to clipboard

A Flutter plugin for Twilio Conversations which allows you to build engaging conversational messaging experiences on iOS and Android platforms.

pub package


twilio_chat_conversation



Introduction #

A Flutter plugin for Twilio Conversations which allows you to build engaging conversational messaging experiences for Android and iOS.

Supported platforms #

  • Android
  • iOS

Features #

  • 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

Example #

Check out the example

Usage #

Obtain an instance #

final TwilioChatConversation twilioChatConversationPlugin = TwilioChatConversation();
copied to clipboard

Generate token (Only Android) #

// 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 twilioChatConversationPlugin.generateToken(accountSid:credentials['accountSid'],apiKey:credentials['apiKey'],apiSecret:credentials['apiSecret'],identity:credentials['identity'],serviceSid: credentials['serviceSid']);
copied to clipboard

Initialize conversation client with the access token #

/// 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 twilioChatConversationPlugin.initializeConversationClient(accessToken: accessToken);
copied to clipboard

Create new conversation #

final String? result = await twilioChatConversationPlugin.createConversation(conversationName:conversationName, identity: identity);
copied to clipboard

Get list of conversations for logged in user #

final List result = await twilioChatConversationPlugin.getConversations() ?? [];
copied to clipboard

Get messages from the specific conversation #

final  List result = await twilioChatConversationPlugin.getMessages(conversationId: conversationId) ?? [];
copied to clipboard

Join an existing conversation #

final String? result = await twilioChatConversationPlugin.joinConversation(conversationId:conversationId);
copied to clipboard

Send message #

final String? result = await twilioChatConversationPlugin.sendMessage(message:enteredMessage,conversationId:conversationId);
copied to clipboard

Add participant in a conversation #

final String? result = await twilioChatConversationPlugin.addParticipant(participantName:participantName,conversationId:conversationId);
copied to clipboard

Remove participant from a conversation #

final String? result = await twilioChatConversationPlugin.removeParticipant(participantName:participantName,conversationId:conversationId);
copied to clipboard

Get participants from the specific conversation #

final  List result = await twilioChatConversationPlugin.getParticipants(conversationId: conversationId) ?? [];
copied to clipboard

Subscribe to message update #

/// Use this method to listen to newly added messages in a conversation
twilioChatConversationPlugin.subscribeToMessageUpdate(conversationSid:widget.conversationSid);
twilioChatConversationPlugin.onMessageReceived.listen((event) {
});
copied to clipboard

Unsubscribe to message update #

/// Use this method to receive newly added messages in a conversation
twilioChatConversationPlugin.unSubscribeToMessageUpdate(conversationSid: widget.conversationSid);
copied to clipboard

Listen to access token expiration #

twilioChatConversationPlugin.onTokenStatusChange.listen((tokenData) {
if (tokenData["statusCode"] == 401){
     generateAndUpdateAccessToken()
   }
});
copied to clipboard

Update access token #

/// 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 twilioChatConversationPlugin.updateAccessToken(accessToken:accessToken);
copied to clipboard

License #

MIT License

Issues and feedback #

If you have any suggestions for including a feature or if something doesn't work, feel free to open a Github issue or to open a pull request, you are more than welcome to contribute!

Contributor #

30
likes
150
points
84
downloads

Publisher

verified publisherzingworks.in

Weekly Downloads

2024.09.16 - 2025.03.31

A Flutter plugin for Twilio Conversations which allows you to build engaging conversational messaging experiences on iOS and Android platforms.

Documentation

API reference

License

MIT (license)

Dependencies

flutter, plugin_platform_interface

More

Packages that depend on twilio_chat_conversation