You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

97 lines
3.0 KiB

4 years ago
import 'package:bytedesk_kefu/bytedesk_kefu.dart';
4 years ago
import 'package:bytedesk_kefu/util/bytedesk_constants.dart';
import 'package:bytedesk_kefu/util/bytedesk_events.dart';
4 years ago
import 'package:flutter/material.dart';
void main() {
// runApp(MyApp());
runApp(MaterialApp(
debugShowCheckedModeBanner: false, // 去除右上角debug的标签
home: MyApp(),
));
// 管理后台https://www.bytedesk.com/antv/user/login
// 参考文档https://github.com/pengjinning/bytedesk-android
// appkey和subDomain请替换为真实值
// 获取appkey登录后台->客服管理->渠道管理->添加应用->appkey
4 years ago
String _androidKey = "66390193-b2c1-4edb-aa5f-50b1541059e8";
String _iOSKey = "201809171553112";
4 years ago
// 获取subDomain也即企业号登录后台->客服管理->客服账号->企业号
String _subDomain = "vip";
// 第一步:匿名登录
4 years ago
BytedeskKefu.anonymousLogin(_androidKey, _iOSKey, _subDomain);
4 years ago
}
class MyApp extends StatefulWidget {
@override
_MyAppState createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
//
String _title = '萝卜丝客服Demo';
// 到 客服管理->技能组-有一列 唯一IDwId, 默认设置工作组wid
String _workGroupWid = "201807171659201";
//
@override
void initState() {
super.initState();
_listener();
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(_title),
elevation: 0,
),
body: ListView(
children: <Widget>[
ListTile(
title: Text('联系客服'),
trailing: Icon(Icons.keyboard_arrow_right),
onTap: () {
print('chat');
// 第二步:联系客服,完毕
BytedeskKefu.startWorkGroupChat(context, _workGroupWid, "技能组客服");
},
)
],
),
);
}
// 监听状态
_listener() {
// 监听连接状态
4 years ago
bytedeskEventBus.on<ConnectionEventBus>().listen((event) {
4 years ago
print('长连接状态:' + event.content);
4 years ago
if (event.content == BytedeskConstants.USER_STATUS_CONNECTING) {
4 years ago
setState(() {
_title = "萝卜丝客服Demo(连接中...)";
});
4 years ago
} else if (event.content == BytedeskConstants.USER_STATUS_CONNECTED) {
4 years ago
setState(() {
_title = "萝卜丝客服Demo(连接成功)";
});
4 years ago
} else if (event.content == BytedeskConstants.USER_STATUS_DISCONNECTED) {
4 years ago
setState(() {
_title = "萝卜丝客服Demo(连接断开)";
});
}
});
// 监听消息
4 years ago
bytedeskEventBus.on<ReceiveMessageEventBus>().listen((event) {
4 years ago
// print('receive message:' + event.message.content);
4 years ago
if (event.message.type == BytedeskConstants.MESSAGE_TYPE_TEXT) {
4 years ago
print('文字消息: ' + event.message.content);
4 years ago
} else if (event.message.type == BytedeskConstants.MESSAGE_TYPE_IMAGE) {
4 years ago
print('图片消息:' + event.message.imageUrl);
} else {
print('其他类型消息');
}
});
}
}