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

[MSE-191] Reimplement Ada chat with webview_flutter #15

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
2d04958
wip: Rewriting with webview_flutter package
slava-r-epam Jun 19, 2024
fd76457
wip: Fix compile errors in lib folder
slava-r-epam Jun 20, 2024
d436aa1
fix: Fix handle
slava-r-epam Jun 20, 2024
076bbf2
fix: Fix JS in AdaController
slava-r-epam Jun 20, 2024
d70112b
fix: Add init and start to _onPageFinished()
slava-r-epam Jun 20, 2024
1bc5de4
wip: Can't load ada
slava-r-epam Jun 20, 2024
93b6f2e
wip: Refactor
slava-r-epam Jun 21, 2024
9cd940e
feat: github.io page is working! Small fixes
slava-r-epam Jun 21, 2024
6fae563
fix: embed.html uri of example
slava-r-epam Jun 21, 2024
71034e8
wip: getInfo() is not working
slava-r-epam Jun 21, 2024
785dfaf
wip: getInfo() is not working
slava-r-epam Jun 21, 2024
ee30d1e
wip: Headers are not helping to fix zoom on android
slava-r-epam Jun 21, 2024
7aba591
wip: Even iPhone headers are not helping
slava-r-epam Jun 21, 2024
a72c0f9
wip: Open link outside of the chat
slava-r-epam Jun 24, 2024
b53f2b8
feat: Update values like page Title and backIsAvailable from the cont…
slava-r-epam Jun 24, 2024
e6af878
fix: Small fixes
slava-r-epam Jun 24, 2024
be28da3
wip: POC that Ada button can be disabled
slava-r-epam Jun 24, 2024
a84ce5d
wip: Comment out POC for future development
slava-r-epam Jun 24, 2024
186fdfc
fix: Fix in app browser on android
slava-r-epam Jun 24, 2024
3a37725
fix: Fix getInfo()
slava-r-epam Jun 25, 2024
3cd9c7e
fix: Fix ada chat on iOS
slava-r-epam Jun 25, 2024
9be39c2
fix: Add progress. Refactor with ListenableBuilder.
slava-r-epam Jun 25, 2024
b880f1f
fix: Simplify ProgressBar
slava-r-epam Jun 25, 2024
dabd951
refactor: Rename some in PageControls
slava-r-epam Jun 25, 2024
473cf55
chore: Add todo
slava-r-epam Jun 25, 2024
b60392e
doc: Update README.md
slava-r-epam Jun 25, 2024
dcf8af5
doc: Fix README.md
slava-r-epam Jun 25, 2024
e7fdc66
feat: Remove exceptions. Fix README.md
slava-r-epam Jun 25, 2024
95dd932
fix: Fix ada_controller_init_test.dart and ada_controller_test.dart
slava-r-epam Jun 25, 2024
43dd760
refactor: Refactor progress calculation
slava-r-epam Jun 25, 2024
fa719b3
test: Fix tests
slava-r-epam Jun 25, 2024
d80b407
fix: Small fixes
slava-r-epam Jun 25, 2024
fa577eb
fix: pubspec.yaml small fixes
slava-r-epam Jun 25, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 46 additions & 4 deletions packages/ada_chat_flutter/README.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,55 @@
# ada_chat_flutter Package

This package provides a widget for integrating Ada chat into your Flutter application.
It uses the `flutter_inappwebview` package to display the chat interface.
It uses the `webview_flutter` package to display the chat interface. The same package is used to
show internal browser if user taps on link in the chat.

## Features

- Customizable chat settings
- Event callbacks
- Customizable chat settings.
- Customizable in app web browser look and controls.
- Various events callbacks.

## Usage

Check the example folder.
Check the example folder.

## AdaWebView parameters

### embedUri parameter

File with following content should be placed somewhere on your web server.

```html
<!DOCTYPE html>
<html>

<head>
<meta charset="utf-8"/>
<meta name="viewport" content="width=device-width, initial-scale=1" />

<script type="text/javascript">
window.adaSettings = {
parentElement: "content_frame",
lazy: true
};
</script>

<script defer id="__ada" src="https://static.ada.support/embed2.js"></script>
</head>

<body style="position: absolute; bottom: 0px; top: 0px; left: 0px; right: 0px; margin: 0; padding: 0;">
<div id="content_frame" style="height: 100%; width: 100%"></div>
</body>

</html>
```

Link to that html file must be passed as `embedUri` parameter to `AdaWebView` widget.

Don't forget to add yor domain to the allow list on Ada dashboard.

### handle parameter

Another required parameter is handle. This is your bot handle from Ada dashboard.

18 changes: 9 additions & 9 deletions packages/ada_chat_flutter/analysis_options.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,19 @@ include: package:flutter_lints/flutter.yaml

linter:
rules:
use_key_in_widget_constructors: false
no_adjacent_strings_in_list: false
literal_only_boolean_expressions: false
prefer_single_quotes: false
slash_for_doc_comments: false
avoid_void_async: true
constant_identifier_names: false
curly_braces_in_flow_control_structures: false
literal_only_boolean_expressions: false
no_adjacent_strings_in_list: false
non_constant_identifier_names: false
omit_local_variable_types: false
use_function_type_syntax_for_parameters: false
prefer_const_constructors: false
non_constant_identifier_names: false
constant_identifier_names: false
avoid_void_async: true
require_trailing_commas: true
slash_for_doc_comments: false
unawaited_futures: true
use_function_type_syntax_for_parameters: false
use_key_in_widget_constructors: false

analyzer:
exclude:
Expand Down
30 changes: 1 addition & 29 deletions packages/ada_chat_flutter/example/analysis_options.yaml
Original file line number Diff line number Diff line change
@@ -1,29 +1 @@
# This file configures the analyzer, which statically analyzes Dart code to
# check for errors, warnings, and lints.
#
# The issues identified by the analyzer are surfaced in the UI of Dart-enabled
# IDEs (https://dart.dev/tools#ides-and-editors). The analyzer can also be
# invoked from the command line by running `flutter analyze`.

# The following line activates a set of recommended lints for Flutter apps,
# packages, and plugins designed to encourage good coding practices.
include: package:flutter_lints/flutter.yaml

linter:
# The lint rules applied to this project can be customized in the
# section below to disable rules from the `package:flutter_lints/flutter.yaml`
# included above or to enable additional rules. A list of all available lints
# and their documentation is published at
# https://dart-lang.github.io/linter/lints/index.html.
#
# Instead of disabling a lint rule for the entire project in the
# section below, it can also be suppressed for a single line of code
# or a specific dart file by using the `// ignore: name_of_lint` and
# `// ignore_for_file: name_of_lint` syntax on the line or in the file
# producing the lint.
rules:
# avoid_print: false # Uncomment to disable the `avoid_print` rule
# prefer_single_quotes: true # Uncomment to enable the `prefer_single_quotes` rule

# Additional information about this file can be found at
# https://dart.dev/guides/language/analysis-options
include: ../analysis_options.yaml
50 changes: 23 additions & 27 deletions packages/ada_chat_flutter/example/lib/screens/ada_chat_screen.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import 'dart:developer';

import 'package:ada_chat_flutter/ada_chat_flutter.dart';
import 'package:example/webview_controls/page_with_controls.dart';
import 'package:example/widgets/commands_menu.dart';
import 'package:example/widgets/progress_bar.dart';
import 'package:flutter/material.dart';

class AdaChatScreen extends StatefulWidget {
Expand All @@ -17,7 +20,7 @@ class AdaChatScreen extends StatefulWidget {

class _AdaChatScreenState extends State<AdaChatScreen> {
final _adaController = AdaController();
var _progress = 0.0;
var _progress = 0;

@override
Widget build(BuildContext context) => SafeArea(
Expand All @@ -34,6 +37,9 @@ class _AdaChatScreenState extends State<AdaChatScreen> {
body: Stack(
children: [
AdaWebView(
urlRequest: Uri.parse(
'https://your.domain.com/embed.html',
),
handle: 'example-handle',
name: 'User 1',
email: 'qqq@google.com',
Expand All @@ -54,13 +60,8 @@ class _AdaChatScreenState extends State<AdaChatScreen> {
'keySens': 'valueSens',
},
onProgressChanged: (progress) => setState(() {
_progress = progress / 100;
_progress = progress;
}),
onAdaReady: (isRolledOut) {
debugPrint(
'AdaChatScreen:onAdaReady: isRolledOut=$isRolledOut');
setState(() => _progress = 0);
},
browserSettings: BrowserSettings(
pageBuilder: (context, browser, controller) => Scaffold(
body: SafeArea(
Expand All @@ -71,32 +72,27 @@ class _AdaChatScreenState extends State<AdaChatScreen> {
),
),
),
onLoaded: (data) =>
debugPrint('AdaChatScreen:onLoaded: data=$data'),
onEvent: (event) =>
debugPrint('AdaChatScreen:onEvent: event=$event'),
onLoaded: (data) => log('AdaChatScreen:onLoaded: data=$data'),
onAdaReady: (isRolledOut) {
log('AdaChatScreen:onAdaReady: isRolledOut=$isRolledOut');
setState(() => _progress = 0);
},
onEvent: (event) => log('AdaChatScreen:onEvent: event=$event'),
onConsoleMessage: (level, message) =>
debugPrint('AdaChatScreen:onConsoleMessage: '
log('AdaChatScreen:onConsoleMessage: '
'level=$level, message=$message'),
onConversationEnd: (event) =>
debugPrint('AdaChatScreen:onConversationEnd: event=$event'),
onDrawerToggle: (isDrawerOpen) => debugPrint(
'AdaChatScreen:onConversationEnd: isDrawerOpen=$isDrawerOpen'),
onLoadingError: (request, error) =>
debugPrint('AdaChatScreen:onLoadingError: '
'request=$request, error=$error'),
),
AnimatedPositioned(
duration: const Duration(milliseconds: 500),
top: _isNotLoading ? -5 : 0,
left: 0,
right: 0,
child: LinearProgressIndicator(value: _progress, minHeight: 5),
log('AdaChatScreen:onConversationEnd: event=$event'),
onDrawerToggle: (isDrawerOpen) =>
log('AdaChatScreen:onDrawerToggle: '
'isDrawerOpen=$isDrawerOpen'),
onLoadingError: (request, response) =>
log('AdaChatScreen:onLoadingError: '
'request=$request, response=$response'),
),
ProgressBar(progress: _progress),
],
),
),
);

bool get _isNotLoading => _progress == 0 || _progress == 1;
}
Loading
Loading