respondo_sdk 0.1.2
respondo_sdk: ^0.1.2 copied to clipboard
Native Respondo support-chat SDK for Flutter: chat, news, surveys, banners, checklists and push notifications in pure Dart, with no native code.
example/lib/main.dart
import 'package:flutter/material.dart';
import 'package:path_provider/path_provider.dart';
import 'package:respondo_sdk/respondo_sdk.dart';
/// Minimal Respondo SDK integration.
///
/// Replace the agent and channel IDs with the values from your Respondo
/// dashboard (Channels → Widget). No API key is required: the SDK talks to
/// your public widget channel.
Future<void> main() async {
WidgetsFlutterBinding.ensureInitialized();
// Persist the visitor session so conversations survive app restarts.
// Omit storageDirectory to keep the session in memory only.
final supportDir = await getApplicationSupportDirectory();
await Respondo.init(
RespondoConfig(
agentId: '<agent-uuid>',
channelId: '<channel-uuid>',
storageDirectory: supportDir.path,
),
);
// Optional: open links from support messages with your own launcher.
Respondo.onUrlRequested = (url) {
debugPrint('Support link tapped: $url');
return true;
};
runApp(const ExampleApp());
}
class ExampleApp extends StatelessWidget {
const ExampleApp({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Respondo Example',
// Lets the SDK present the chat bottom-sheet without a host context.
navigatorKey: Respondo.navigatorKey,
home: const HomePage(),
);
}
}
class HomePage extends StatelessWidget {
const HomePage({super.key});
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: const Text('Respondo Example')),
body: Center(
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
// Live unread badge for your support entry point.
StreamBuilder<int>(
stream: Respondo.unreadCountStream,
initialData: 0,
builder: (context, snapshot) =>
Text('Unread messages: ${snapshot.data}'),
),
const SizedBox(height: 16),
ElevatedButton(
onPressed: Respondo.open,
child: const Text('Open support chat'),
),
const SizedBox(height: 16),
ElevatedButton(
onPressed: () {
// Recognize a signed-in user. userHash is an HMAC computed by
// YOUR backend — never ship the identity secret in the app.
Respondo.identify(
RespondoIdentity(
userId: 'u_123',
email: 'jane@example.com',
userHash: '<hmac-from-your-backend>',
),
);
},
child: const Text('Identify signed-in user'),
),
const SizedBox(height: 16),
ElevatedButton(
// On logout: revoke the session and start a fresh visitor.
onPressed: Respondo.reset,
child: const Text('Reset (logout)'),
),
],
),
),
);
}
}