atlas_support_sdk 1.3.1 copy "atlas_support_sdk: ^1.3.1" to clipboard
atlas_support_sdk: ^1.3.1 copied to clipboard

Atlas customer support chat widget

Atlas customer support chat widget for Flutter

Getting started #

To use it with Android you may need to ensure that AndroidManifest.xml includes <uses-permission android:name="android.permission.INTERNET" />

Usage #

You can run sample application by changing credentials in the main.dart file.

Using the widget to add the chat #

import 'package:atlas_support_sdk/atlas_support_widget.dart';

// Use widget:
AtlasSupportWidget(appId: "...", userId: "...", userHash: "...", onError: print)

Listening for stats changes #

Each conversation stat instance contains id, unread (amount of unread messages), and closed flag.

import 'package:atlas_support_sdk/watch_atlas_support_stats.dart';

// Listen:
class _MyWidgetState extends State<MyWidget> {
  int _unreadCount = 0;
  Function? _unsubscribe = null;

  @override
  void initState() {
    super.initState();
    _unsubscribe = watchAtlasSupportStats(
        appId: "...",
        userId: "...",
        userHash: "...",
        onStatsChange: (stats) {
          setState(() {
            _unreadCount = stats.conversations
                .fold(0, (sum, conversation) => sum + conversation.closed ? 0 : conversation.unread);
          });
        },
        onError: print);
  }

  @override
  void dispose() {
    _unsubscribe?.call();
    super.dispose();
  }

  // ...
}

Updating user custom fields #

import 'package:atlas_support_sdk/update_atlas_custom_fields.dart';

AtlasSupportWidget(
  appId: "...",
  onNewTicket: (data) {
    updateAtlasCustomFields(
      "...", // atlasId
      data["ticketId"], // ticketId
      {"prop": "value"}, // customFields
      // If needed:
      userHash: "...",
    );
  },
);

Using instance with shared settings #

Using SDK instance you can change user for all widgets and watches by calling sdk.identify(userId: "...", userHash: "...").

import 'package:atlas_support_sdk/atlas_support_sdk.dart';

// Listen:
class _MyWidgetState extends State<MyWidget> {
  int _unreadCount = 0;
  Function? _unsubscribe = null;
  AtlasSupportSDK atlasSdk = createAtlasSupportSDK(appId: "...", userId: "...", userHash: "...", onError: print);

  @override
  void initState() {
    super.initState();
    _unsubscribe = atlasSdk.watchStats((stats) {
      setState(() {
        _unreadCount = stats.conversations
            .fold(0, (sum, conversation) => sum + conversation.closed ? 0 : conversation.unread);
      });
    });
  }

  @override
  void dispose() {
    _unsubscribe?.call();
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: atlasSdk.Widget(
        onNewTicket: (data) {
          atlasSdk.updateCustomFields(
            data["ticketId"], // ticketId
            {"prop": "value"}, // customFields
          );
        },
      )
    );
  }

  // ...
}

When using the widget via SDK instance you can also persist its state to prevent loading Atlas more than once. Use persist property with the unique string value at any place and after the initial load the app will render immediately:

sdk.Widget(persist: "main")