requestAgent method

Future<RequestThreadResult> requestAgent(
  1. String? wid,
  2. String? type,
  3. String? aid
)

Implementation

Future<RequestThreadResult> requestAgent(
    String? wid, String? type, String? aid) async {
  //
  final threadUrl = BytedeskUtils.getHostUri('/api/thread/request/agent',
      {'wId': wid, 'type': type, 'aId': aid, 'client': client});
  debugPrint("request agent Url $threadUrl");
  final initResponse = await httpClient.get(threadUrl, headers: getHeaders());

  //解决json解析中的乱码问题
  Utf8Decoder utf8decoder = const Utf8Decoder(); // fix 中文乱码
  //将string类型数据 转换为json类型的数据
  final responseJson =
      json.decode(utf8decoder.convert(initResponse.bodyBytes));
  debugPrint("requestAgent $responseJson");
  // 判断token是否过期
  if (responseJson.toString().contains('invalid_token')) {
    bytedeskEventBus.fire(InvalidTokenEventBus());
  }

  return RequestThreadResult.fromJson(responseJson);
}