Skip to main content

helpr_chat 0.1.0 copy "helpr_chat: ^0.1.0" to clipboard
helpr_chat: ^0.1.0 copied to clipboard

Helpr support chat for Flutter apps — conversations, live replies, wallet context and issue intake forms over Helpr's public client API.

example/lib/main.dart

// A sample app (a pretend web3 wallet) with Helpr support built in: a Support button with an unread badge, the
// customer's Messages list and chat with the inbox's AI assistant and team, attachments, and the connected wallet shared
// with support.
//
// Run it against your Helpr (an API inbox, with an AI assistant connected for AI answers):
//
//   flutter run \
//     --dart-define=HELPR_BASE_URL=https://support.example.com \
//     --dart-define=HELPR_INBOX=<api inbox identifier>
//
// To try a signed-in customer, also pass HELPR_USER_ID and HELPR_USER_HASH (HMAC-SHA256 of the user id with the inbox's
// HMAC token, computed by YOUR server, never in the app). For a local Helpr over http, the URL is allowed in debug
// builds only (use 10.0.2.2 instead of localhost on the Android emulator).
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:helpr_chat/helpr_chat.dart';

import 'home_screen.dart';

const baseUrl = String.fromEnvironment('HELPR_BASE_URL', defaultValue: 'http://127.0.0.1:3000');
const inboxIdentifier = String.fromEnvironment('HELPR_INBOX');
const userId = String.fromEnvironment('HELPR_USER_ID');
const userHash = String.fromEnvironment('HELPR_USER_HASH');

void main() {
  if (inboxIdentifier.isEmpty) {
    runApp(const _MissingConfig());
    return;
  }
  // One client for the whole app: it keeps the customer's session and the single live connection.
  final client = HelprClient(
    api: HelprApi(baseUrl: Uri.parse(baseUrl), inboxIdentifier: inboxIdentifier, allowInsecure: kDebugMode),
  );
  runApp(ExampleApp(
      client: client,
      demoUser: userId.isEmpty
          ? null
          : HelprIdentity(
              identifier: userId, identifierHash: userHash.isEmpty ? null : userHash, name: 'Demo customer')));
}

class ExampleApp extends StatelessWidget {
  const ExampleApp({super.key, required this.client, this.demoUser});

  final HelprClient client;
  final HelprIdentity? demoUser;

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Helpr example',
      theme: ThemeData(colorSchemeSeed: const Color(0xFF1B1F3B), useMaterial3: true),
      darkTheme: ThemeData(colorSchemeSeed: const Color(0xFF1B1F3B), brightness: Brightness.dark, useMaterial3: true),
      home: HomeScreen(client: client, demoUser: demoUser),
    );
  }
}

class _MissingConfig extends StatelessWidget {
  const _MissingConfig();

  @override
  Widget build(BuildContext context) => const MaterialApp(
        home: Scaffold(
          body: Center(
            child: Padding(
              padding: EdgeInsets.all(24),
              child: Text(
                'Pass your Helpr API inbox identifier:\n\nflutter run --dart-define=HELPR_INBOX=<identifier> '
                '--dart-define=HELPR_BASE_URL=<your Helpr URL>',
                textAlign: TextAlign.center,
              ),
            ),
          ),
        ),
      );
}
0
likes
150
points
--
downloads

Documentation

API reference

Publisher

unverified uploader

Weekly Downloads

Helpr support chat for Flutter apps — conversations, live replies, wallet context and issue intake forms over Helpr's public client API.

Homepage

License

MIT (license)

Dependencies

flutter, flutter_secure_storage, http, http_parser, web_socket_channel

More

Packages that depend on helpr_chat