connectToLineModular method
Connect this bot to a line channel with the "modular" approach.
-
{callbackUrl} is the url that will be called after the connection is completed, either successfully or not.
-
{autoRedirect} is whether to automatically redirect the page to the line login page or not. Default is true.
If {autoRedirect} is true,
-- On desktop and mobile, this will automatically open the line login page in the browser.
-- On web, this will redirect the page to the line login page. This is only used when {autoRedirect} is true and the platform is web.
Implementation
Future<String?> connectToLineModular({
required String callbackUrl,
bool autoRedirect = true,
bool newWindow = false,
}) async {
try {
if (_bot.id == null) {
GetIt.I<BotnoiClient>().finishedFailed();
GetIt.I<BotnoiClient>().error.add("[connectToLineModular] : bot '${_bot.botName}' doesn't have an id, try reloading it");
return null;
}
Uri url = Uri.parse(
"${GetIt.I<BotnoiClient>().endpoint}/developer/platform-api/connect/line-modular?bot_id=${_bot.id}&callback=$callbackUrl");
http.Response response = await http.get(
url,
headers: _getHeader,
);
if (response.statusCode == 200) {
GetIt.I<BotnoiClient>().finishedSuccessfully();
dynamic result = jsonDecode(utf8.decode(response.bodyBytes));
if (autoRedirect) {
if (kIsWeb && !newWindow) {
html.window.open(result["redirect_url"], "_self");
} else {
launchUrlString(result["redirect_url"]);
}
}
return result["redirect_url"].toString();
}
GetIt.I<BotnoiClient>().finishedFailed();
GetIt.I<BotnoiClient>().error.add("[connectToLineModular] : ${response.reasonPhrase}");
return null;
} catch (e) {
GetIt.I<BotnoiClient>().finishedFailed();
GetIt.I<BotnoiClient>().error.add("[connectToLineModular] : $e");
return null;
}
}