requestThread method

Future<RequestThreadResult> requestThread(
  1. String? sid,
  2. String? type,
  3. bool? forceAgent
)

Implementation

Future<RequestThreadResult> requestThread(String? sid,  String? type, bool? forceAgent) async {
  //
  String orgUid = SpUtil.getString(BytedeskConstants.VISITOR_ORGUID)!;
  String uid = SpUtil.getString(BytedeskConstants.VISITOR_UID)!;
  String nickname = SpUtil.getString(BytedeskConstants.VISITOR_NICKNAME)!;
  String avatar = SpUtil.getString(BytedeskConstants.VISITOR_AVATAR)!;
  //
  final requestThreadUrl =
      BytedeskUtils.getHostUri('/visitor/api/v1/thread', {
    'orgUid': orgUid,
    'type': type,
    'sid': sid,
    //
    'uid': uid,
    'nickname': nickname,
    'avatar': avatar,
    //
    'forceAgent': forceAgent.toString(),
    'client': client
  });
  final requestThreadResponse = await httpClient.get(requestThreadUrl,
      headers: getHeadersForVisitor());
  //解决json解析中的乱码问题
  Utf8Decoder utf8decoder = const Utf8Decoder(); // fix 中文乱码
  //将string类型数据 转换为json类型的数据
  final responseJson =
      json.decode(utf8decoder.convert(requestThreadResponse.bodyBytes));
  debugPrint("$requestThreadUrl requestThread responseJson $responseJson");

  return RequestThreadResult.fromJson(responseJson);
}