|
|
@ -1,29 +1,25 @@
|
|
|
|
import 'package:bytedesk_kefu/bytedesk_kefu.dart';
|
|
|
|
import 'package:bytedesk_kefu/bytedesk_kefu.dart';
|
|
|
|
import 'package:bytedesk_kefu/util/bytedesk_constants.dart';
|
|
|
|
import 'package:bytedesk_kefu/util/bytedesk_constants.dart';
|
|
|
|
import 'package:bytedesk_kefu/util/bytedesk_events.dart';
|
|
|
|
import 'package:bytedesk_kefu/util/bytedesk_events.dart';
|
|
|
|
|
|
|
|
import 'package:bytedesk_kefu/util/bytedesk_utils.dart';
|
|
|
|
|
|
|
|
import 'package:bytedesk_demo/notification/custom_notification.dart';
|
|
|
|
import 'package:bytedesk_demo/page/chat_type_page.dart';
|
|
|
|
import 'package:bytedesk_demo/page/chat_type_page.dart';
|
|
|
|
import 'package:bytedesk_demo/page/history_thread_page.dart';
|
|
|
|
import 'package:bytedesk_demo/page/history_thread_page.dart';
|
|
|
|
import 'package:bytedesk_demo/page/online_status_page.dart';
|
|
|
|
import 'package:bytedesk_demo/page/online_status_page.dart';
|
|
|
|
// import 'package:bytedesk_demo/page/setting_page.dart';
|
|
|
|
import 'package:bytedesk_demo/page/setting_page.dart';
|
|
|
|
import 'package:bytedesk_demo/page/user_info_page.dart';
|
|
|
|
import 'package:bytedesk_demo/page/user_info_page.dart';
|
|
|
|
import 'package:bytedesk_kefu/util/bytedesk_utils.dart';
|
|
|
|
|
|
|
|
import 'package:overlay_support/overlay_support.dart';
|
|
|
|
import 'package:overlay_support/overlay_support.dart';
|
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
|
|
|
|
import 'package:vibration/vibration.dart';
|
|
|
|
import 'notification/custom_notification.dart';
|
|
|
|
import 'package:audioplayers/audio_cache.dart';
|
|
|
|
|
|
|
|
|
|
|
|
void main() {
|
|
|
|
void main() {
|
|
|
|
// runApp(MyApp());
|
|
|
|
// runApp(MyApp());
|
|
|
|
// runApp(MaterialApp(
|
|
|
|
|
|
|
|
// debugShowCheckedModeBanner: false, // 去除右上角debug的标签
|
|
|
|
|
|
|
|
// home: MyApp(),
|
|
|
|
|
|
|
|
// ));
|
|
|
|
|
|
|
|
runApp(OverlaySupport(
|
|
|
|
runApp(OverlaySupport(
|
|
|
|
child: MaterialApp(
|
|
|
|
child: MaterialApp(
|
|
|
|
debugShowCheckedModeBanner: false, // 去除右上角debug的标签
|
|
|
|
debugShowCheckedModeBanner: false, // 去除右上角debug的标签
|
|
|
|
home: MyApp(),
|
|
|
|
home: MyApp(),
|
|
|
|
)
|
|
|
|
)));
|
|
|
|
));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 参考文档:https://github.com/Bytedesk/bytedesk-flutter
|
|
|
|
// 参考文档:https://github.com/Bytedesk/bytedesk-flutter
|
|
|
|
// 管理后台:https://www.bytedesk.com/antv/user/login
|
|
|
|
// 管理后台:https://www.bytedesk.com/antv/user/login
|
|
|
@ -45,8 +41,7 @@ class MyApp extends StatefulWidget {
|
|
|
|
class _MyAppState extends State<MyApp> with WidgetsBindingObserver {
|
|
|
|
class _MyAppState extends State<MyApp> with WidgetsBindingObserver {
|
|
|
|
//
|
|
|
|
//
|
|
|
|
String _title = '萝卜丝客服Demo';
|
|
|
|
String _title = '萝卜丝客服Demo';
|
|
|
|
// 第二步:到 客服管理->技能组-有一列 ‘唯一ID(wId)’, 默认设置工作组wid
|
|
|
|
AudioCache audioCache = AudioCache();
|
|
|
|
// String _workGroupWid = "201807171659201";
|
|
|
|
|
|
|
|
//
|
|
|
|
//
|
|
|
|
@override
|
|
|
|
@override
|
|
|
|
void initState() {
|
|
|
|
void initState() {
|
|
|
@ -81,6 +76,7 @@ class _MyAppState extends State<MyApp> with WidgetsBindingObserver {
|
|
|
|
title: Text('用户信息'), // 自定义用户资料,设置
|
|
|
|
title: Text('用户信息'), // 自定义用户资料,设置
|
|
|
|
trailing: Icon(Icons.keyboard_arrow_right),
|
|
|
|
trailing: Icon(Icons.keyboard_arrow_right),
|
|
|
|
onTap: () {
|
|
|
|
onTap: () {
|
|
|
|
|
|
|
|
// 需要首先调用anonymousLogin之后,再调用设置用户信息接口
|
|
|
|
Navigator.of(context)
|
|
|
|
Navigator.of(context)
|
|
|
|
.push(new MaterialPageRoute(builder: (context) {
|
|
|
|
.push(new MaterialPageRoute(builder: (context) {
|
|
|
|
return new UserInfoPage();
|
|
|
|
return new UserInfoPage();
|
|
|
@ -123,16 +119,16 @@ class _MyAppState extends State<MyApp> with WidgetsBindingObserver {
|
|
|
|
// // TODO: 意见反馈
|
|
|
|
// // TODO: 意见反馈
|
|
|
|
// },
|
|
|
|
// },
|
|
|
|
// ),
|
|
|
|
// ),
|
|
|
|
// ListTile(
|
|
|
|
ListTile(
|
|
|
|
// title: Text('消息设置'),
|
|
|
|
title: Text('消息设置'),
|
|
|
|
// trailing: Icon(Icons.keyboard_arrow_right),
|
|
|
|
trailing: Icon(Icons.keyboard_arrow_right),
|
|
|
|
// onTap: () {
|
|
|
|
onTap: () {
|
|
|
|
// Navigator.of(context)
|
|
|
|
Navigator.of(context)
|
|
|
|
// .push(new MaterialPageRoute(builder: (context) {
|
|
|
|
.push(new MaterialPageRoute(builder: (context) {
|
|
|
|
// return new SettingPage();
|
|
|
|
return new SettingPage();
|
|
|
|
// }));
|
|
|
|
}));
|
|
|
|
// },
|
|
|
|
},
|
|
|
|
// )
|
|
|
|
)
|
|
|
|
],
|
|
|
|
],
|
|
|
|
).toList()),
|
|
|
|
).toList()),
|
|
|
|
);
|
|
|
|
);
|
|
|
@ -157,9 +153,30 @@ class _MyAppState extends State<MyApp> with WidgetsBindingObserver {
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
// 监听消息
|
|
|
|
// 监听消息,开发者可在此决定是否振动或播放提示音声音
|
|
|
|
bytedeskEventBus.on<ReceiveMessageEventBus>().listen((event) {
|
|
|
|
bytedeskEventBus.on<ReceiveMessageEventBus>().listen((event) {
|
|
|
|
// print('receive message:' + event.message.content);
|
|
|
|
// print('receive message:' + event.message.content);
|
|
|
|
|
|
|
|
// 1. 首先将example/assets/audio文件夹中文件拷贝到自己项目;2.在自己项目pubspec.yaml中添加assets
|
|
|
|
|
|
|
|
// 播放发送消息提示音
|
|
|
|
|
|
|
|
if (BytedeskKefu.getPlayAudioOnSendMessage() && event.message.isSend == 1) {
|
|
|
|
|
|
|
|
print('play send audio');
|
|
|
|
|
|
|
|
// 修改为自己项目中语音文件路径
|
|
|
|
|
|
|
|
audioCache.play('audio/bytedesk_dingdong.wav');
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (event.message.isSend == 1) {
|
|
|
|
|
|
|
|
// 自己发送的消息,直接返回
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
// 接收消息播放提示音
|
|
|
|
|
|
|
|
if (BytedeskKefu.getPlayAudioOnReceiveMessage() && event.message.isSend == 0) {
|
|
|
|
|
|
|
|
print('play receive audio');
|
|
|
|
|
|
|
|
audioCache.play('audio/bytedesk_dingdong.wav');
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
// 振动
|
|
|
|
|
|
|
|
if (BytedeskKefu.getVibrateOnReceiveMessage() && event.message.isSend == 0) {
|
|
|
|
|
|
|
|
print('should vibrate');
|
|
|
|
|
|
|
|
vibrate();
|
|
|
|
|
|
|
|
}
|
|
|
|
if (event.message.type == BytedeskConstants.MESSAGE_TYPE_TEXT) {
|
|
|
|
if (event.message.type == BytedeskConstants.MESSAGE_TYPE_TEXT) {
|
|
|
|
print('文字消息: ' + event.message.content);
|
|
|
|
print('文字消息: ' + event.message.content);
|
|
|
|
// 判断当前是否客服页面,如否,则显示顶部通知栏
|
|
|
|
// 判断当前是否客服页面,如否,则显示顶部通知栏
|
|
|
@ -176,9 +193,10 @@ class _MyAppState extends State<MyApp> with WidgetsBindingObserver {
|
|
|
|
);
|
|
|
|
);
|
|
|
|
}, duration: Duration(milliseconds: 4000));
|
|
|
|
}, duration: Duration(milliseconds: 4000));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
} else if (event.message.type == BytedeskConstants.MESSAGE_TYPE_IMAGE) {
|
|
|
|
} else if (event.message.type == BytedeskConstants.MESSAGE_TYPE_IMAGE) {
|
|
|
|
print('图片消息:' + event.message.imageUrl);
|
|
|
|
print('图片消息:' + event.message.imageUrl);
|
|
|
|
|
|
|
|
} else if (event.message.type == BytedeskConstants.MESSAGE_TYPE_VIDEO) {
|
|
|
|
|
|
|
|
print('视频消息:' + event.message.imageUrl);
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
print('其他类型消息');
|
|
|
|
print('其他类型消息');
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -202,10 +220,15 @@ class _MyAppState extends State<MyApp> with WidgetsBindingObserver {
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void vibrate() async {
|
|
|
|
|
|
|
|
if (await Vibration.hasVibrator()) {
|
|
|
|
|
|
|
|
Vibration.vibrate();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
@override
|
|
|
|
void dispose() {
|
|
|
|
void dispose() {
|
|
|
|
WidgetsBinding.instance.removeObserver(this);
|
|
|
|
WidgetsBinding.instance.removeObserver(this);
|
|
|
|
super.dispose();
|
|
|
|
super.dispose();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|