atlas_support_sdk 1.4.1 copy "atlas_support_sdk: ^1.4.1" to clipboard
atlas_support_sdk: ^1.4.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")

Widget query parameter #

An optional query parameter in string format. The query is used to configure the behavior or content of the embeded chat widget.

// Initiate widget and immediately start chatbot with report_bug key (chatbotKey: report_bug), or open the last one if exists (prefer: last)
AtlasSupportWidget(appId: "...", query: "chatbotKey: report_bug; prefer: last")
// or
atlasSdk.Widget(query: "chatbotKey: report_bug; prefer: last")

// Initiate widget and immediately open helpcenter
atlasSdk.Widget(query: "open: helpcenter")

chatbotKey: key: (optional) Specifies the chatbot that has to be started immediately when AtlasFragment is loaded

prefer: last: (optional) Instead of starting new chatbot everytime it will open the last not completed chatbot if exists

open: helpcenter Starts widget with HelpCenter screen

0
likes
100
points
358
downloads

Publisher

unverified uploader

Weekly Downloads

Atlas customer support chat widget

Homepage

Documentation

API reference

License

MIT (license)

Dependencies

flutter, http, shared_preferences, web_socket_channel, webview_flutter, webview_flutter_android, webview_flutter_wkwebview, yaml

More

Packages that depend on atlas_support_sdk