From 01d8b06e7b827d43f2da0b720e51a9fb529320a3 Mon Sep 17 00:00:00 2001 From: jack ning Date: Fri, 25 Mar 2022 14:58:46 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E6=9F=A5=E8=AF=A2=E6=9C=AA?= =?UTF-8?q?=E8=AF=BB=E6=B6=88=E6=81=AF=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 1 + bytedesk_demo/lib/page/chat_type_page.dart | 80 +++++++++++++++------- bytedesk_demo/pubspec.yaml | 2 +- 3 files changed, 56 insertions(+), 27 deletions(-) diff --git a/README.md b/README.md index 4be0c17..b17e15b 100644 --- a/README.md +++ b/README.md @@ -18,6 +18,7 @@ - 消息撤回 - 输入状态(对方正在输入) - 发送/播放视频 +- 查询未读消息数 diff --git a/bytedesk_demo/lib/page/chat_type_page.dart b/bytedesk_demo/lib/page/chat_type_page.dart index 0d28bbe..725e320 100755 --- a/bytedesk_demo/lib/page/chat_type_page.dart +++ b/bytedesk_demo/lib/page/chat_type_page.dart @@ -6,7 +6,7 @@ import 'package:flutter/material.dart'; // 多种客服对话类型列表页面 class ChatTypePage extends StatefulWidget { - ChatTypePage({Key? key}) : super(key: key); + const ChatTypePage({Key? key}) : super(key: key); @override _ChatTypePageState createState() => _ChatTypePageState(); @@ -15,39 +15,57 @@ class ChatTypePage extends StatefulWidget { class _ChatTypePageState extends State { // 第二步:到 客服管理->技能组-有一列 ‘唯一ID(wId)’, 默认设置工作组wid // 说明:一个技能组可以分配多个客服,访客会按照一定的规则分配给组内的各个客服账号 - String _workGroupWid = "201807171659201"; // 默认人工 - String _workGroupWidRobot = "201809061716221"; // 默认机器人, 在管理后台开启或关闭机器人 + final String _workGroupWid = "201807171659201"; // 默认人工 + final String _workGroupWidRobot = "201809061716221"; // 默认机器人, 在管理后台开启或关闭机器人 // 说明:直接发送给此一个客服账号,一对一会话 - String _agentUid = "201808221551193"; + final String _agentUid = "201808221551193"; + // 未读消息数目 + String _unreadMessageCount = "0"; + // + @override + void initState() { + // 加载未读消息数目 + _getUnreadCountVisitor(); + // + super.initState(); + } // @override Widget build(BuildContext context) { return Scaffold( appBar: AppBar( - title: Text('对话类型'), + title: const Text('对话类型'), elevation: 0, ), body: ListView( children: ListTile.divideTiles(context: context, tiles: [ ListTile( - title: Text('技能组客服'), - trailing: Icon(Icons.keyboard_arrow_right), + title: Text('未读消息数目:' + _unreadMessageCount), + trailing: const Icon(Icons.keyboard_arrow_right), + onTap: () { + // 加载未读消息数目 + _getUnreadCountVisitor(); + }, + ), + ListTile( + title: const Text('技能组客服'), + trailing: const Icon(Icons.keyboard_arrow_right), onTap: () { BytedeskKefu.startWorkGroupChat( context, _workGroupWid, "技能组客服-默认人工"); }, ), ListTile( - title: Text('技能组客服-机器人'), - trailing: Icon(Icons.keyboard_arrow_right), + title: const Text('技能组客服-机器人'), + trailing: const Icon(Icons.keyboard_arrow_right), onTap: () { BytedeskKefu.startWorkGroupChat( context, _workGroupWidRobot, "技能组客服-默认机器人"); }, ), ListTile( - title: Text('技能组客服-电商'), - trailing: Icon(Icons.keyboard_arrow_right), + title: const Text('技能组客服-电商'), + trailing: const Icon(Icons.keyboard_arrow_right), onTap: () { // 商品信息,type/title/content/price/url/imageUrl/id/categoryCode // 注意:长度不能大于500字符 @@ -69,8 +87,8 @@ class _ChatTypePageState extends State { }, ), ListTile( - title: Text('技能组客服-电商-回调'), - trailing: Icon(Icons.keyboard_arrow_right), + title: const Text('技能组客服-电商-回调'), + trailing: const Icon(Icons.keyboard_arrow_right), onTap: () { // 商品信息,type/title/content/price/url/imageUrl/id/categoryCode // 注意:长度不能大于500字符 @@ -99,8 +117,8 @@ class _ChatTypePageState extends State { }, ), ListTile( - title: Text('技能组客服-附言'), - trailing: Icon(Icons.keyboard_arrow_right), + title: const Text('技能组客服-附言'), + trailing: const Icon(Icons.keyboard_arrow_right), onTap: () { BytedeskKefu.startWorkGroupChatPostscript( context, _workGroupWid, "技能组客服-附言", "随便说点什么吧,我会自动发送给客服"); @@ -110,15 +128,15 @@ class _ChatTypePageState extends State { height: 20, ), ListTile( - title: Text('指定一对一客服'), - trailing: Icon(Icons.keyboard_arrow_right), + title: const Text('指定一对一客服'), + trailing: const Icon(Icons.keyboard_arrow_right), onTap: () { BytedeskKefu.startAppointedChat(context, _agentUid, "指定一对一客服"); }, ), ListTile( - title: Text('指定一对一客服-电商'), - trailing: Icon(Icons.keyboard_arrow_right), + title: const Text('指定一对一客服-电商'), + trailing: const Icon(Icons.keyboard_arrow_right), onTap: () { // 商品信息,type/title/content/price/url/imageUrl/id/categoryCode // 注意:长度不能大于500字符 @@ -139,8 +157,8 @@ class _ChatTypePageState extends State { }, ), ListTile( - title: Text('指定一对一客服-电商-回调'), - trailing: Icon(Icons.keyboard_arrow_right), + title: const Text('指定一对一客服-电商-回调'), + trailing: const Icon(Icons.keyboard_arrow_right), onTap: () { // 商品信息,type/title/content/price/url/imageUrl/id/categoryCode // 注意:长度不能大于500字符 @@ -168,8 +186,8 @@ class _ChatTypePageState extends State { }, ), ListTile( - title: Text('指定一对一客服-附言'), - trailing: Icon(Icons.keyboard_arrow_right), + title: const Text('指定一对一客服-附言'), + trailing: const Icon(Icons.keyboard_arrow_right), onTap: () { BytedeskKefu.startAppointedChatPostscript( context, _agentUid, "指定一对一客服-附言", "随便说点什么吧,我会自动发送给客服"); @@ -179,13 +197,13 @@ class _ChatTypePageState extends State { height: 20, ), ListTile( - title: Text('H5网页会话'), - trailing: Icon(Icons.keyboard_arrow_right), + title: const Text('H5网页会话'), + trailing: const Icon(Icons.keyboard_arrow_right), onTap: () { print('h5 chat'); // 注意: 登录后台->客服管理->技能组(或客服账号)->获取客服代码 获取相应URL String url = - "http://www.bytedesk.com/chat?sub=vip&uid=201808221551193&wid=201807171659201&type=workGroup&aid=&hidenav=1&ph=ph"; + "https://h1.kefux.cn/chat/h5/index.html?sub=vip&uid=201808221551193&wid=201807171659201&type=workGroup&aid=&hidenav=1&ph=ph"; String title = 'H5在线客服演示'; BytedeskKefu.startH5Chat(context, url, title); }, @@ -194,4 +212,14 @@ class _ChatTypePageState extends State { ), ); } + + void _getUnreadCountVisitor() { + // 获取指定客服在线状态 + BytedeskKefu.getUnreadCountVisitor().then((count) => { + print('unreadcount:' + count), + setState(() { + _unreadMessageCount = count; + }) + }); + } } diff --git a/bytedesk_demo/pubspec.yaml b/bytedesk_demo/pubspec.yaml index d3717c9..c14de9b 100644 --- a/bytedesk_demo/pubspec.yaml +++ b/bytedesk_demo/pubspec.yaml @@ -46,7 +46,7 @@ dependencies: # 请在ios/Podfile中添加:use_frameworks! vibration: ^1.7.3 # 在线客服 https://pub.dev/packages/bytedesk_kefu - bytedesk_kefu: ^1.2.1 + bytedesk_kefu: ^1.2.2 # The following adds the Cupertino Icons font to your application. # Use with the CupertinoIcons class for iOS style icons.