connectToLineManual method
Connect this bot to a line channel with the "manual" approach.
-
{accessToken} is the access token of the line channel.
-
{secret} is the secret of the line channel.
Implementation
Future<void> connectToLineManual({
required String accessToken,
required String secret,
}) async {
try {
if (_bot.id == null) {
GetIt.I<BotnoiClient>().finishedFailed();
GetIt.I<BotnoiClient>().error.add("[connectToLineManual] : bot '${_bot.botName}' doesn't have an id, try reloading it");
return;
}
Uri url = Uri.parse("${GetIt.I<BotnoiClient>().endpoint}/developer/platform-api/connect/line-manual");
http.Response response = await http.put(
url,
headers: _getHeader,
body: jsonEncode({
"bot_id": _bot.id,
"first_token": accessToken,
"second_token": secret,
"active": (_bot.accessChannel!["line"] as List).isNotEmpty,
}),
);
if (response.statusCode == 200 || response.statusCode == 204 || response.statusCode == 201) {
GetIt.I<BotnoiClient>().finishedSuccessfully();
return;
}
GetIt.I<BotnoiClient>().finishedFailed();
GetIt.I<BotnoiClient>().error.add("[connectToLineManual] : ${response.reasonPhrase ?? "ERROR"}");
return;
} catch (e) {
GetIt.I<BotnoiClient>().finishedFailed();
GetIt.I<BotnoiClient>().error.add("[connectToLineManual] : $e");
return;
}
}