chatsasa_chat_sdk 1.0.2 chatsasa_chat_sdk: ^1.0.2 copied to clipboard
Welcome to the ChatSasa Chat SDK. This SDK allows you to easily integrate ChatSasa's chat functionality into your Flutter mobile applications.
ChatSasa Chat-SDK #
Welcome to the ChatSasa Chat-SDK. This SDK allows you to easily integrate chat functionality into your Flutter mobile applications.
Getting started #
For you to start using Chatsasa Chat-SDK you need to first create an account on ChatSasa developer dashboard.
Here are the steps to get you started.
- Create an account in developer.chatsasa.com dashboard.
- Create an organisation
- Create an app.
- Add Users to your App.
API Integration #
- On your backend application use the provided API endpoints to register and login users.
- Provide ChatSasa-API token to mobile users.
Add dependency #
Add chatsasa_chat_sdk to your package's pubspec.yaml file, use the latest version.
dependencies:
chatsasa_chat_sdk: ^latest_version
You should then run flutter packages get
Changelog #
Check out the changelog on pub.dev to see the latest changes in the package.
Initialization #
Initialize the ChatSasa SDK in your main.dart file:
import 'package:flutter/material.dart';
import 'package:chatsasa_chat_sdk/chatsasa_chat_sdk.dart';
void main() {
WidgetsFlutterBinding.ensureInitialized();
await ChatSasaChatSDK().initSDK();
runApp(const MyApp());
}
Prerequisites #
- An authentication chat-api token for user authentication (chatApiToken) - Get from your backend after successfully creating an organization.
- An application ID (appId), typically got from thedeveloper.chatsasa.com dashboard.
- An FCM token fromFirebase FCM for your application (fcmToken) for push notification support. If you intend to use push notifications for real-time message updates, ensure that you have obtained an FCM token (fcmToken) from Firebase Cloud Messaging for your app. This token is required to enable push notifications within the ChatSasa chat-SDK.
Usage #
To list your chat channels, use the following code:
chatApiToken
: 'Your chat-api-token',appId
: 'Your chat-api application_id',fcmToken
: 'Your fcm_token'
import 'package:flutter/material.dart';
import 'package:chatsasa_chat_sdk/barrel.dart';
class MyHomePage extends StatefulWidget {
const MyHomePage({super.key,});
@override
State<MyHomePage> createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
backgroundColor: Colors.blue,
title: Text(
"ChatSasa Chat-SDK Example",
style: const TextStyle(color: Colors.white),
),
),
body: Center(
child: Container(),
),
floatingActionButton: FloatingActionButton(
onPressed: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (_) =>
//Launch ChatSasa Chat Channels
ChatChannels(
```chatApiToken```: 'Your chat-api-token',
```appId```: 'Your chat-api application_id',
```fcmToken```: 'Your fcm_token'
))
);
},
tooltip: 'launch chat',
child: const Icon(Icons.chat_bubble_outline),
),
);
}
}
Add FCM push messaging #
To enable the Firebase Cloud messaging to your application, follow these steps:
-
Foreground notifications #
To enable FCM notifications when your app is in foreground modify the FirebaseMessaging.onMessage.listen()
method as below.
FirebaseMessaging.onMessage.listen((message) {
//Add_this_code
ChatSasaChatSDK().handleFCMEvents(message.data);
var notificationMessage =
ChatSasaChatSDK().getFCMNotification(message.data);
//show LocalNotificationService from flutter_local_notifications package you can use other notification packages of your preference
LocalNotificationService()
.showNotificationAndroid(notificationMessage as Map<String, dynamic>);
//END
});
-
Background nofitications #
To receive FCM notifications when your app is running in the background modify the _firebaseMessagingBackgroundHandler
method as below.
@pragma('vm:entry-point')
Future<void> _firebaseMessagingBackgroundHandler(RemoteMessage message) async {
// Add_this_code
var notificationMessage = ChatSasaChatSDK().getFCMNotification(message.data);
// LocalNotificationService from flutter_local_notifications package you can use other notification packages of your preference
LocalNotificationService()
.showNotificationAndroid(notificationMessage as Map<String, dynamic>);
//END
}