v2.4.7crisp_chat
एंड्रॉइड और आईओएस पर क्रिस्प चैट का मूल रूप से उपयोग करने के लिए एक फ्लटर प्लगइन पैकेज।
एंड्रॉइड और आईओएस पर क्रिस्प चैट का मूल रूप से उपयोग करने के लिए एक फ्लटर प्लगइन पैकेज।
^0.3.0{"sdk":"flutter"}{"sdk":"flutter"}^1.6.0^2.1.8^6.3.2^1.1.1{"sdk":"flutter"}>=2.0.0 <7.0.0यह अंग्रेज़ी मूल स्नैपशॉट है। नवीनतम सामग्री GitHub पर देखें।
A Flutter plugin for Crisp live chat on Android, iOS, Web, and desktop (macOS, Windows, Linux).
Crisp Chat
pub version Last Commit License GitHub Contributors Stars GitHub Closed Issues Sponsors Buy Me A Coffee
Chat with website visitors, integrate your favorite tools, and deliver a great customer experience. On mobile, the plugin uses the official Crisp Android and iOS SDKs. On Web and desktop, it uses the official Crisp Web Chat SDK (embedded chatbox or desktop WebView). The same Dart API covers session data, events, and REST helpers where supported.
📖 Full Documentation — Comprehensive guides, API reference, and examples.
Note: Contributions are highly appreciated. If you have an idea or suggestion to improve this package, feel free to reach out. Before contributing, please review the CONTRIBUTING.md file for guidelines and setup instructions.
CrispWebRTC SDK)| Platform | How chat opens | Extra setup |
|---|---|---|
| Android | Native Crisp SDK | Internet permission, compileSdk / minSdk |
| iOS | Native Crisp SDK | Privacy keys in Info.plist; optional video via $CrispChatWebRTC (CocoaPods) or CRISP_CHAT_WEBRTC (SPM) |
| Web | Crisp Web Chat SDK ($crisp) |
Valid websiteID; optional CSP for client.crisp.chat |
| macOS / Windows / Linux | Web SDK in WebView (or browser) | Desktop main() helper; macOS network entitlement; WebView2 / WebKitGTK |
Full API differences: Supported platforms in the docs.
First, add crisp_chat as a dependency in your pubspec.yaml file.
To use the Flutter Crisp Chat, simply import the crisp_chat package:
Run this on your project terminal:
flutter pub add crisp_chat
or manually configure pubspec.yml file
dependencies:
flutter:
sdk: flutter
crisp_chat: ^2.8.0
Web / desktop: No native Crisp SDK install. Web loads client.crisp.chat at runtime. Desktop uses an embedded WebView (desktop_webview_window) or opens your browser if WebView is unavailable. See Supported platforms in the docs.
Configure permissions and push as below. Web and desktop only need a valid websiteID unless you use REST unread helpers (prefer a backend proxy on web).
Add three rows to the ios/Runner/Info.plist:
Privacy - Camera Usage Description and a usage description.Privacy - Photo Library Additions Usage Description and a usage description.Privacy - Microphone Usage Description and a usage description.If editing Info.plist as text, add:
<key>NSCameraUsageDescription</key>
<string>your usage description here</string>
<key>NSPhotoLibraryAddUsageDescription</key>
<string>your usage description here</string>
<key>NSMicrophoneUsageDescription</key>
<string>your usage description here</string>
Optional — video/audio calls (iOS only): CocoaPods: $CrispChatWebRTC = true in ios/Podfile, then pod install. SPM (Flutter 3.44+ default): CRISP_CHAT_WEBRTC=true flutter build ios. Adds ~10 MB. Android native video is not supported yet by Crisp. See Platform setup — Enable video calls.
Add Internet permission on AndroidManifest.xml in your android/app/src/main/AndroidManifest.xml file.
<uses-permission android:name="android.permission.INTERNET"/>
Change the minimum Compile SDK version to 35 (or higher) in your android/app/build.gradle file.
compileSdkVersion 36
Change the minimum Android SDK version to 21 (or higher) in your android/app/build.gradle file.
minSdkVersion 23
AndroidManifest.xml (If your app declares a FileProvider in its AndroidManifest.xml)<provider android:name="androidx.core.content.FileProvider"
android:authorities="${applicationId}.fileprovider;${applicationId}.im.crisp.client.uploadfileprovider"
android:exported="false"
android:grantUriPermissions="true"
tools:replace="android:authorities">
<meta-data android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/file_paths"
tools:replace="android:resource" />
</provider>
and res/xml/file_paths.xml add this
<files-path name="crisp_sdk_attachments" path="im.crisp.client/attachments/" />
No native SDK install. The plugin loads https://client.crisp.chat/l.js when you call openCrispChat.
flutter create . --platforms=webUser.signature when it is a real HMAC-SHA256 hex string from your server (32+ hex characters). Placeholder values can leave the chat stuck on the loading skeleton.https://client.crisp.chat and https://*.crisp.chatRun the example:
cd example && flutter run -d chrome --dart-define=websiteId=YOUR_WEBSITE_ID
Uses the same Crisp Web Chat SDK in an embedded window (desktop_webview_window), or opens the system browser if WebView is unavailable.
flutter create . --platforms=macos,windows,linuxmain() before runApp (required for embedded WebView):import 'package:desktop_webview_window/desktop_webview_window.dart';
import 'package:flutter/foundation.dart';
Future<void> main(List<String> args) async {
WidgetsFlutterBinding.ensureInitialized();
if (!kIsWeb &&
(defaultTargetPlatform == TargetPlatform.macOS ||
defaultTargetPlatform == TargetPlatform.windows ||
defaultTargetPlatform == TargetPlatform.linux)) {
if (runWebViewTitleBarWidget(args)) return;
}
runApp(const MyApp());
}
macos/Runner/DebugProfile.entitlements and Release.entitlements:<key>com.apple.security.network.client</key>
<true/>
sudo apt install libwebkit2gtk-4.1-devopenChatboxFromNotification, setOnNotificationTappedCallback, onCrispEvent, and CrispConfig.enableNotifications do not apply on Web/desktop.
See Supported platforms for the API matrix and troubleshooting.
Note: Sections 3–ix below are for mobile push notifications only. Web and desktop do not use FCM/APNs through this plugin.
In order to complete this step, follow the Firebase Get started guide.
At the end of it, also add the following dependency to your project.
flutter pub add firebase_core
flutter pub add firebase_messaging
Copy your Firebase Cloud Messaging Sender ID
Generate and download your Firebase Admin private key
Enable Push Notifications in Crisp dashboard
Crisp checking FCM Credentials
Crisp checking FCM Credentials
You have two options for handling Crisp push notifications:
Declare the Crisp CrispNotificationService in the <application> tag of your AndroidManifest.xml.
<service
android:name="im.crisp.client.external.notification.CrispNotificationService"
android:exported="false">
<intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT" />
</intent-filter>
</service>
Notifications will be handled by Crisp CrispNotificationService and a tap on it will launch your MainActivity and automatically open the Crisp ChatActivity with the corresponding session.
If you want your app to open first (so the user sees your app UI) and then open the Crisp chatbox programmatically, use the SDK's CrispChatNotificationService instead:
<service
android:name="com.alaminkarno.flutter_crisp_chat.CrispChatNotificationService"
android:exported="false">
<intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT" />
</intent-filter>
</service>
Then in your Flutter code, handle the notification tap to open the chatbox:
@override
void initState() {
super.initState();
// Handle app launched from a Crisp notification (terminated state)
FlutterCrispChat.openChatboxFromNotification();
// Handle notification tap while app is in the background
FlutterCrispChat.setOnNotificationTappedCallback(() {
FlutterCrispChat.openChatboxFromNotification();
});
}
openChatboxFromNotification() — Checks if the app was launched from a Crisp notification and opens the chatbox. Returns true if successful, false otherwise.setOnNotificationTappedCallback(callback) — Sets a callback that fires when a Crisp notification is tapped while the app is already running in the background.Crisp Push notifications customizable in 3 ways: color, icon and sound.
For the first two, you can update them from your AndroidManifest.xml as you would do with Firebase.
<application>
<meta-data
android:name="com.google.firebase.messaging.default_notification_icon"
android:resource="@drawable/my_notification_icon"
tools:replace="android:resource" />
<meta-data
android:name="com.google.firebase.messaging.default_notification_color"
android:resource="@color/my_notification_color"
tools:replace="android:resource" />
</application>
For the sound, you can add a raw resource named crisp_chat_message_receive to your app which will be played upon notification receipt.
Push Notifications
To enable Crisp push notifications on iOS, you must register for remote notifications in your app's AppDelegate.swift.
➡️ Step: Add the following inside didFinishLaunchingWithOptions:
DispatchQueue.main.async {
UIApplication.shared.registerForRemoteNotifications()
}
Currently, push notifications are only sent to production APNs channels. Notifications will not be received when testing with development provisioning profiles or in sandbox mode. This limitation will be resolved in a future update.import 'package:firebase_core/firebase_core.dart';
import 'firebase_options.dart';
Future<void> main() async {
WidgetsFlutterBinding.ensureInitialized();
await Firebase.initializeApp(
options: DefaultFirebaseOptions.currentPlatform,
);
runApp(const MyApp());
}
On iOS, and Android 13 (or newer), before FCM payloads can be received on your device, you must first ask the user's permission.
FirebaseMessaging messaging = FirebaseMessaging.instance;
NotificationSettings settings = await messaging.requestPermission(
alert: true,
announcement: false,
badge: true,
carPlay: false,
criticalAlert: false,
provisional: false,
sound: true,
);
print('User granted permission: ${settings.authorizationStatus}');
The process of handling background messages is different on native Android and Apple platforms.
There are a few things to keep in mind about your background message handler:
@pragma('vm:entry-point') right above the function declaration (otherwise it may be removed during tree shaking for release mode).import 'package:firebase_core/firebase_core.dart';
import 'package:firebase_messaging/firebase_messaging.dart';
import 'firebase_options.dart';
@pragma('vm:entry-point')
Future<void> _firebaseMessagingBackgroundHandler(RemoteMessage message) async {
// If you're going to use other Firebase services in the background, such as Firestore,
// make sure you call `initializeApp` before using other Firebase services.
await Firebase.initializeApp();
print("Handling a background message: ${message.messageId}");
}
Future<void> main() async {
WidgetsFlutterBinding.ensureInitialized();
await Firebase.initializeApp(
options: DefaultFirebaseOptions.currentPlatform,
);
FirebaseMessaging.onBackgroundMessage(_firebaseMessagingBackgroundHandler);
runApp(const MyApp());
}
Go to your Crisp Dashboard, and copy your Website ID:
Crisp Dashboard
Here's a more detailed example of how to configure CrispConfig and use the plugin methods. To open ChatView for crisp, use the openCrispChat method of the FlutterCrispChat class:
import 'package:flutter/material.dart';
import 'package:crisp_chat/crisp_chat.dart';
import 'package:flutter/foundation.dart'; // For kDebugMode
class CrispChatPage extends StatefulWidget {
const CrispChatPage({super.key});
@override
State<CrispChatPage> createState() => _CrispChatPageState();
}
class _CrispChatPageState extends State<CrispChatPage> {
final String websiteID = 'YOUR_WEBSITE_ID'; // Replace with your actual Website ID
final String identifier = 'YOUR_CRISP_API_IDENTIFIER'; // Replace with your actual Crisp API Identifier
final String crispApiKey = 'YOUR_CRISP_API_KEY'; // Replace with your actual Crisp API Key
int count = 0;
late CrispConfig _crispConfig;
@override
void initState() {
super.initState();
// Handle Crisp notification tap (Option B only - see section 3.iii)
// Opens the chatbox if the app was launched from a Crisp notification (terminated state)
FlutterCrispChat.openChatboxFromNotification();
// Listen for Crisp notification taps while the app is in the background
FlutterCrispChat.setOnNotificationTappedCallback(() {
FlutterCrispChat.openChatboxFromNotification();
});
// Configure Crisp User (Optional)
// All user fields are optional. Only provide what you have.
final crispUser = User(
email: "user@example.com",
signature: "USER_EMAIL_HMAC_SHA256_SIGNATURE",
nickName: "John Doe",
phone: "1234567890",
avatar: "https://example.com/avatar.png",
company: Company(
name: "Example Corp",
url: "https://example.com",
companyDescription: "A sample company providing excellent services.",
employment: Employment(title: "Lead Developer", role: "Software Engineer"),
geoLocation: GeoLocation(city: "New York", country: "USA"),
),
);
// 1. Initialize CrispConfig with all desired parameters.
_crispConfig = CrispConfig(
websiteID: websiteID, // [required] Your Crisp website ID.
tokenId: "your_user_token_id_optional", // Optional: Assign a unique token to this session.
sessionSegment: "beta_testers", // Optional: Assign a segment to categorize users (e.g., "premium", "trial").
user: crispUser, // Optional: Provide user details.
enableNotifications: true, // Optional: Enable or disable push notifications. Defaults to true.
modalPresentationStyle: ModalPresentationStyle.fullScreen, // Optional: iOS modal presentation style. Defaults to fullScreen.
);
// 2. Optionally, set additional session data *before* opening the chat.
// This data is associated with the session when it's created or next resumed.
// Useful for sending custom attributes that might not fit into the User object.
FlutterCrispChat.setSessionString(key: "custom_data_point", value: "some_important_value");
FlutterCrispChat.setSessionInt(key: "user_score", value: 120);
FlutterCrispChat.setSessionSegments(segments: ["registered_user", "newsletter_subscriber"], overwrite: false);
}
void _openChat() async {
// 3. Open the Crisp Chat UI using the prepared configuration.
await FlutterCrispChat.openCrispChat(config: _crispConfig);
// 4. Optionally, retrieve the session identifier after the chat is opened.
// This can be useful for logging or internal tracking.
String? sessionId = await FlutterCrispChat.getSessionIdentifier();
if (sessionId != null) {
if (kDebugMode) {
print('Crisp Session ID: $sessionId');
}
} else {
if (kDebugMode) {
print('No active Crisp session found or an error occurred while retrieving the ID.');
}
}
}
void _resetSession() async {
// Call resetCrispChatSession, for example, when your app user logs out.
// This is crucial for privacy and ensuring that the next user (or a guest)
// does not see or interact with the previous user's chat history and data
// within the Crisp SDK session on the device.
await FlutterCrispChat.resetCrispChatSession();
if (kDebugMode) {
print('Crisp session has been reset. The previous user\'s data is cleared from the local SDK session.');
}
}
void _checkUnreadMessages() async {
// Call getUnreadMessageCount to check for unread messages.
int? unreadCount = await FlutterCrispChat.getUnreadMessageCount(
websiteId: websiteID,
identifier: identifier,
key: crispApiKey,
);
if (unreadCount != null && unreadCount > 0) {
if (kDebugMode) {
print('You have $unreadCount unread messages.');
}
setState(() {
count = unreadCount;
});
}
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('Crisp Chat Example'),
),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
ElevatedButton(
onPressed: _openChat,
child: const Text('Open Crisp Chat (Full Config)'),
),
const SizedBox(height: 20),
ElevatedButton(
onPressed: _resetSession,
child: const Text('Reset Crisp Session'),
),
const SizedBox(height: 20),
Badge.count(
count: count,
isLabelVisible: count != 0,
maxCount: 9,
child: ElevatedButton(
onPressed: _checkUnreadMessages,
child: Text('Unread'),
),
)
],
),
),
);
}
}
To use this code, replace YOUR_WEBSITE_ID with your own website ID from the Crisp dashboard. The example demonstrates initializing CrispConfig with detailed user and company information, setting additional session data, opening the chat interface, retrieving the session ID, and resetting the session. Adjust the configuration and data according to your application's needs.
The modalPresentationStyle parameter in CrispConfig allows you to control how the Crisp chat view is presented on iOS devices. This is particularly important for preventing touch events from passing through to the underlying Flutter UI.
ModalPresentationStyle.fullScreen (Default) - The view controller covers the entire screen. This prevents touch events from passing through to the underlying UI.ModalPresentationStyle.pageSheet - The view controller is displayed as a page sheet with a dimmed background.ModalPresentationStyle.formSheet - The view controller is displayed as a form sheet, centered on the screen.ModalPresentationStyle.overFullScreen - The view controller covers the screen but allows underlying content to show through.ModalPresentationStyle.overCurrentContext - The view controller is displayed over the parent view controller's content.ModalPresentationStyle.popover - Popover on iPad (centered); on iPhone UIKit adapts to full screen.// Using pageSheet presentation style
final config = CrispConfig(
websiteID: 'YOUR_WEBSITE_ID',
modalPresentationStyle: ModalPresentationStyle.pageSheet,
);
// Using formSheet presentation style
final formSheetConfig = CrispConfig(
websiteID: 'YOUR_WEBSITE_ID',
modalPresentationStyle: ModalPresentationStyle.formSheet,
);
Note: This parameter is iOS-specific and will only affect iOS devices. On Android, the chat will always use the platform's default presentation behavior. On Web and desktop, it is ignored.
Crisp video/audio calls are iOS-only and opt-in at build time (not a CrispConfig flag). Default builds use the standard Crisp SDK without calls.
| Build system | Enable video |
|---|---|
| CocoaPods | $CrispChatWebRTC = true in ios/Podfile, then pod install |
| SPM | CRISP_CHAT_WEBRTC=true flutter build ios |
Check at runtime:
final supported = await FlutterCrispChat.isVideoCallsSupported();
// true on iOS WebRTC builds, Web, and desktop; false on Android and default iOS builds
Adds ~10 MB to the iOS binary. Android native video is not supported yet by Crisp. Full setup: Enable video calls (iOS only).
Open the Crisp Helpdesk/FAQ interface directly without going through the live chat. Useful when you want to direct users to self-service help content.
Platform support: All platforms — Android, iOS, Web, macOS, Windows, and Linux. Android/iOS use the native SDK; Web and desktop use the Crisp Web Chat SDK (
$crisp.push).
await FlutterCrispChat.openHelpdesk(websiteId: 'YOUR_WEBSITE_ID');
await FlutterCrispChat.openHelpdeskArticle(
websiteId: 'YOUR_WEBSITE_ID',
locale: 'en', // article language code
slug: 'article-slug', // article slug from your Crisp Helpdesk dashboard
title: 'Optional title', // optional
category: 'Optional cat', // optional
);
The slug for an article can be found in the Crisp dashboard under Helpdesk → open the article → the URL contains the slug. Both methods throw ArgumentError if required fields are empty.
For every request that you make to getUnreadMessageCount or markMessagesAsRead, you must submit your authentication token (identifier and key), as well as your website_id.
::: tip iOS unread count
On iOS, unread.visitor may not reset after reading chat in the native SDK. Call FlutterCrispChat.markMessagesAsRead() after the visitor closes chat. See docs/unread-count-verification.md.
:::
Obtaining Identifier & Key:
identifier/key pairBefore using your development token, you now need to associate your marketplace account to your Crisp workspace. This is done by specifying a Trusted Workspace:
website_idListen to native Crisp SDK events — useful for updating an unread badge in real time instead of polling getUnreadMessageCount().
Platform support: Android and iOS only. The stream never emits on Web/desktop.
final subscription = FlutterCrispChat.onCrispEvent.listen((event) {
switch (event.type) {
case CrispEventType.sessionLoaded:
print('Session loaded: ${event.sessionId}');
case CrispEventType.chatOpened:
print('Chat opened');
case CrispEventType.chatClosed:
print('Chat closed');
case CrispEventType.messageSent:
case CrispEventType.messageReceived:
print('Message from ${event.message?.from}: ${event.message?.text}');
case CrispEventType.notificationReceived:
print('Notification data: ${event.notificationData}'); // Android-only
}
});
// Later, when no longer needed:
await subscription.cancel();
The native event callback is registered on the first .listen() call and unregistered once the last listener cancels, so it's safe to listen and cancel freely.
CrispMessage (carried by messageSent/messageReceived events) is a minimal summary — isMe, from, origin, timestamp, fingerprint, contentType, and text (only populated when contentType is CrispMessageContentType.text). Rich content (carousel targets, picker choices, file/audio metadata) is not mapped in this version.
CrispEventType.notificationReceived is Android-only — the iOS Crisp SDK has no matching callback, so iOS never emits it.
Run a Bot scenario configured in the Bot plugin on your Crisp website — useful for kicking off an automated flow (e.g. onboarding, FAQ triage) from within your app.
Platform support: All platforms — Android, iOS, Web, macOS, Windows, and Linux.
await FlutterCrispChat.runBotScenario(scenarioId: 'YOUR_SCENARIO_ID');
The scenario ID can be found in the Crisp dashboard under Settings → Chatbot. Throws ArgumentError if scenarioId is empty.
Crisp Chat SDK for Android
This plugin aims to stay compatible with the latest Crisp SDKs. As of the latest update, it has been tested with:
2.0.242.13.0https://client.crisp.chat/l.js at runtime (Web and desktop)Minimum for Web/desktop (v2.5.0+): Flutter 3.24.0+, Dart 3.5.0+
While the plugin may work with other versions, using versions close to these is recommended for optimal compatibility. Please refer to the official Crisp SDK documentation for the most current SDK details.
| https://avatars.githubusercontent.com/alamin-karno |
|---|
| Md. Al-Amin |
You can chat with them on crisp or follow them on Twitter at Crisp_im.
This project is licensed under the MIT License - see the LICENSE file for details.