Skip to content

Commit

Permalink
v1.4.0
Browse files Browse the repository at this point in the history
Feat: CustomParams
  • Loading branch information
Mastersam07 authored Dec 12, 2021
2 parents 47d0b6d + cd8bb1a commit 3d34b32
Show file tree
Hide file tree
Showing 10 changed files with 124 additions and 13 deletions.
4 changes: 3 additions & 1 deletion .github/workflows/deploy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,10 @@ jobs:
"refreshToken":"${{ secrets.OAUTH_REFRESH_TOKEN }}",
"tokenEndpoint":"https://accounts.google.com/o/oauth2/token",
"scopes": [ "openid", "https://www.googleapis.com/auth/userinfo.email" ],
"expiration": 1603814695612
"expiration": ${{ secrets.EXPIRATION }}
}
EOF
- name: Check Publish Warnings
run: pub publish --dry-run
- name: Publish package
run: pub publish -f
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# ChangeLog for livechat

## 1.4.0

* Add support for custom params.

## 1.3.0

* Bump native dependencies.
Expand Down
17 changes: 16 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ A livechat package for embedding mobile chat window in your mobile application.

```yaml
dependencies:
livechatt: "^1.3.0"
livechatt: "^1.4.0"
```
### ⚡️ Import
Expand Down Expand Up @@ -72,12 +72,27 @@ end

### Dart Usage

- Regular usage

```dart
onPressed: (){
Livechat.beginChat(LICENSE_NO, GROUP_ID, VISITOR_NAME, VISITOR_EMAIL);
},
```

- Cases where there are custom parameters

```dart
var cmap = <String, String>{
'org': 'organizationTextController.text',
'position': 'positionTextController.text'
};
onPressed: (){
Livechat.beginChat(LICENSE_NO, GROUP_ID, VISITOR_NAME, VISITOR_EMAIL, cmap);
},
```

For more info, please, refer to the `main.dart` in the example.

### Views
Expand Down
19 changes: 15 additions & 4 deletions android/src/main/java/tech/mastersam/livechat/LivechatPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,13 @@
import com.livechatinc.inappchat.ChatWindowView;
import com.livechatinc.inappchat.models.NewMessageModel;

import java.util.HashMap;

/// Implement chat bubble
// import com.google.android.material.floatingactionbutton.FloatingActionButton;
// import com.livechatinc.inappchat.ChatWindowEventsListener;
// import com.livechatinc.inappchat.ChatWindowUtils;

/** LivechatPlugin */
public class LivechatPlugin implements FlutterPlugin, MethodCallHandler, ActivityAware{
/// The MethodChannel that will the communication between Flutter and native Android
Expand Down Expand Up @@ -68,6 +75,7 @@ public void onMethodCall(@NonNull MethodCall call, @NonNull Result result) {
result.success("Android " + android.os.Build.VERSION.RELEASE);
} else if (call.method.equals("beginChat")) {
final String licenseNo = call.argument("licenseNo");
final HashMap<String,String> customParams = call.argument("customParams");
final String groupId = call.argument("groupId");
final String visitorName = call.argument("visitorName");
final String visitorEmail = call.argument("visitorEmail");
Expand All @@ -83,12 +91,15 @@ public void onMethodCall(@NonNull MethodCall call, @NonNull Result result) {
Bundle config = new ChatWindowConfiguration.Builder()
.setLicenceNumber(licenseNo)
.setGroupId(groupId)
.setVisitorName(visitorName)
.setVisitorEmail(visitorEmail)
.setCustomParams(customParams)
.build()
.asBundle();
intent.putExtra(com.livechatinc.inappchat.ChatWindowConfiguration.KEY_GROUP_ID, licenseNo);
intent.putExtra(com.livechatinc.inappchat.ChatWindowConfiguration.KEY_LICENCE_NUMBER, groupId);
intent.putExtra(com.livechatinc.inappchat.ChatWindowConfiguration.KEY_VISITOR_NAME, visitorName);
intent.putExtra(com.livechatinc.inappchat.ChatWindowConfiguration.KEY_VISITOR_EMAIL, visitorEmail);
// intent.putExtra(com.livechatinc.inappchat.ChatWindowConfiguration.KEY_GROUP_ID, licenseNo);
// intent.putExtra(com.livechatinc.inappchat.ChatWindowConfiguration.KEY_LICENCE_NUMBER, groupId);
// intent.putExtra(com.livechatinc.inappchat.ChatWindowConfiguration.KEY_VISITOR_NAME, visitorName);
// intent.putExtra(com.livechatinc.inappchat.ChatWindowConfiguration.KEY_VISITOR_EMAIL, visitorEmail);
intent.putExtras(config);
activity.startActivity(intent);

Expand Down
35 changes: 34 additions & 1 deletion example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ class _SupportState extends State<Support> {
final groupIdTextController = TextEditingController();
final visitorNameTextController = TextEditingController();
final visitorEmailTextController = TextEditingController();
final organizationTextController = TextEditingController();
final positionTextController = TextEditingController();

@override
void initState() {
Expand Down Expand Up @@ -136,13 +138,44 @@ class _SupportState extends State<Support> {
SizedBox(
height: 10,
),
Align(
alignment: Alignment.centerLeft,
child: Text(
"Organization",
textAlign: TextAlign.left,
),
),
TextFormField(
keyboardType: TextInputType.text,
controller: organizationTextController,
),
SizedBox(
height: 10,
),
Align(
alignment: Alignment.centerLeft,
child: Text(
"Position",
textAlign: TextAlign.left,
),
),
TextFormField(
keyboardType: TextInputType.text,
controller: positionTextController,
),
SizedBox(
height: 10,
),
CustomButton(
onPress: () {
Livechat.beginChat(
licenseNoTextController.text,
groupIdTextController.text,
visitorNameTextController.text,
visitorEmailTextController.text);
visitorEmailTextController.text, <String, String>{
'org': organizationTextController.text,
'position': positionTextController.text
});
},
title: "Start Live Chat",
),
Expand Down
2 changes: 1 addition & 1 deletion example/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ packages:
path: ".."
relative: true
source: path
version: "1.3.0"
version: "1.4.0"
matcher:
dependency: transitive
description:
Expand Down
4 changes: 4 additions & 0 deletions ios/Classes/SwiftLivechatPlugin.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ public class SwiftLivechatPlugin: NSObject, FlutterPlugin {
let groupId = (arguments["groupId"] as? String)
let visitorName = (arguments["visitorName"] as? String)
let visitorEmail = (arguments["visitorEmail"] as? String)
let customParams = (arguments["customParams"] as! [String:String])

if (licenseNo == ""){
result(FlutterError(code: "", message: "LICENSE NUMBER EMPTY", details: nil))
Expand All @@ -33,6 +34,9 @@ public class SwiftLivechatPlugin: NSObject, FlutterPlugin {
LiveChat.groupId = groupId // Optionally, You can route your customers to specific group of agents by providing groupId
LiveChat.name = visitorName // You can provide customer name or email if they are known, so a customer will not need to fill out the pre-chat survey:
LiveChat.email = visitorEmail // You can provide customer name or email if they are known, so a customer will not need to fill out the pre-chat survey:
for (key, value) in customParams{
LiveChat.setVariable(withKey:key, value:value)
}

LiveChat.presentChat()
result(nil)
Expand Down
6 changes: 4 additions & 2 deletions lib/livechatt.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,15 @@ class Livechat {
}

/// Begin chat by invoking method channel
static Future<void> beginChat(String licenseNo, String groupId,
String visitorName, String visitorEmail) async {
static Future<void> beginChat(
String licenseNo, String groupId, String visitorName, String visitorEmail,
[Map<String, String>? customParams]) async {
await _channel.invokeMethod('beginChat', <String, dynamic>{
'licenseNo': licenseNo,
'groupId': groupId,
'visitorName': visitorName,
'visitorEmail': visitorEmail,
'customParams': customParams,
});
}
}
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: livechatt
description: A livechat package for embedding mobile chat window in your mobile application.
version: 1.3.0
version: 1.4.0
homepage: https://github.com/Mastersam07/livechat
repository: https://github.com/Mastersam07/livechat
issue_tracker: https://github.com/Mastersam07/livechat/issues
Expand Down
44 changes: 42 additions & 2 deletions test/livechatt_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ void main() {
expect(await Livechat.platformVersion, '42');
});

test('can begin chat with plugin', () async {
test('can begin chat with plugin without customParams', () async {
await Livechat.beginChat(
'licenseNo', 'groupId', 'visitorName', 'visitorEmail');
expect(log, <Matcher>[
Expand All @@ -37,6 +37,24 @@ void main() {
'groupId': 'groupId',
'visitorName': 'visitorName',
'visitorEmail': 'visitorEmail',
'customParams': null,
},
),
]);
});

test('can begin chat with plugin with customParams', () async {
await Livechat.beginChat('licenseNo', 'groupId', 'visitorName',
'visitorEmail', {'organization': 'mastersam.xyz'});
expect(log, <Matcher>[
isMethodCall(
'beginChat',
arguments: <String, dynamic>{
'licenseNo': 'licenseNo',
'groupId': 'groupId',
'visitorName': 'visitorName',
'visitorEmail': 'visitorEmail',
'customParams': {'organization': 'mastersam.xyz'},
},
),
]);
Expand All @@ -56,12 +74,33 @@ void main() {
expect(await channel.invokeMethod('getPlatformVersion'), '42');
});

test("can begin chat natively", () async {
test("can begin chat natively without customParams", () async {
channel.invokeMethod('beginChat', <String, dynamic>{
'licenseNo': 'licenseNo',
'groupId': 'groupId',
'visitorName': 'visitorName',
'visitorEmail': 'visitorEmail',
});
expect(log, <Matcher>[
isMethodCall(
'beginChat',
arguments: <String, dynamic>{
'licenseNo': 'licenseNo',
'groupId': 'groupId',
'visitorName': 'visitorName',
'visitorEmail': 'visitorEmail',
},
),
]);
});

test("can begin chat natively with customParams", () async {
channel.invokeMethod('beginChat', <String, dynamic>{
'licenseNo': 'licenseNo',
'groupId': 'groupId',
'visitorName': 'visitorName',
'visitorEmail': 'visitorEmail',
'customParams': {'organization': 'mastersam.xyz'},
});
expect(log, <Matcher>[
isMethodCall(
Expand All @@ -71,6 +110,7 @@ void main() {
'groupId': 'groupId',
'visitorName': 'visitorName',
'visitorEmail': 'visitorEmail',
'customParams': {'organization': 'mastersam.xyz'},
},
),
]);
Expand Down

0 comments on commit 3d34b32

Please sign in to comment.