Skip to content
This repository has been archived by the owner on Aug 14, 2024. It is now read-only.

Commit

Permalink
[MSE-110] Ada chat Flutter implementation. Small fixes (#7)
Browse files Browse the repository at this point in the history
* Add userid test value

* Fix the error "Ada Embed - User is in the wrong rollout group."

* Fix adaReadyCallback parameter

* Show settings

* Set rolloutOverride settings to fix the error: "Ada Embed - User is in the wrong rollout group."

* Change Ada handle for example
  • Loading branch information
slava-r-epam authored May 14, 2024
1 parent 03363ca commit 7233815
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 12 deletions.
13 changes: 8 additions & 5 deletions packages/ada_chat_flutter/example/lib/ada_chat_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -34,28 +34,31 @@ class _AdaChatScreenState extends State<AdaChatScreen> {
body: Stack(
children: [
AdaWebView(
handle: 'headspace-sandbox',
name: 'John Doe',
handle: 'example-handle',
name: 'User 1',
email: '[email protected]',
phone: '+234345566789',
phone: '+5342342131324',
greeting: widget.greeting,
controller: _adaController,
language: 'en',
metaFields: const {
'userid': '1234567890',
'keyStr': 'value3',
'keyBool': false,
'keyDouble': 3.456789,
'keyInt': 42,
'keyNull': null,
},
rolloutOverride: 1,
sensitiveMetaFields: const {
'keySens': 'valueSens',
},
onProgressChanged: (progress) => setState(() {
_progress = progress / 100;
}),
onAdaReady: () {
debugPrint('AdaChatScreen:onAdaReady');
onAdaReady: (isRolledOut) {
debugPrint(
'AdaChatScreen:onAdaReady: isRolledOut=$isRolledOut');
setState(() => _progress = 0);
},
onLoaded: (data) =>
Expand Down
14 changes: 7 additions & 7 deletions packages/ada_chat_flutter/lib/src/ada_web_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ class AdaWebView extends StatefulWidget {
final void Function(int progress)? onProgressChanged;

final void Function(dynamic data)? onLoaded;
final VoidCallback? onAdaReady;
final void Function(dynamic isRolledOut)? onAdaReady;
final void Function(dynamic event)? onEvent;
final void Function(dynamic event)? onConversationEnd;
final void Function(bool isDrawerOpen)? onDrawerToggle;
Expand Down Expand Up @@ -182,15 +182,15 @@ window.adaSettings = {
lazy: true,
parentElement: "content_frame",
onAdaEmbedLoaded: () => {
adaEmbed.subscribeEvent("ada:chat_frame_timeout", (data, context) => {
adaEmbed.subscribeEvent("ada:chat_frame_timeout", (data, context) => {
window.flutter_inappwebview.callHandler("onLoaded", data);
});
});
},
conversationEndCallback: function(event) {
window.flutter_inappwebview.callHandler("onConversationEnd", event);
},
adaReadyCallback: function() {
window.flutter_inappwebview.callHandler("onAdaReady");
adaReadyCallback: function(isRolledOut) {
window.flutter_inappwebview.callHandler("onAdaReady", isRolledOut);
},
toggleCallback: function(isDrawerOpen) {
window.flutter_inappwebview.callHandler("onDrawerToggle", isDrawerOpen);
Expand All @@ -201,7 +201,7 @@ window.adaSettings = {
}
}
};
console.log("adaSettings updated");
console.log("adaSettings: " + JSON.stringify(window.adaSettings));
''',
);

Expand Down Expand Up @@ -243,7 +243,7 @@ console.log("adaSettings updated");

controller.addJavaScriptHandler(
handlerName: 'onAdaReady',
callback: (_) => widget.onAdaReady?.call(),
callback: (isRolledOut) => widget.onAdaReady?.call(isRolledOut),
);

controller.addJavaScriptHandler(
Expand Down

0 comments on commit 7233815

Please sign in to comment.