通过Telegram Bot发送错误消息Flutter



我尝试使用Catcher,这是我的代码

CatcherOptions debugOptions = CatcherOptions(SilentReportMode(), [
ConsoleHandler(),
HttpHandler(HttpRequestType.post,
Uri.parse("https://api.telegram.org/bot<TOKEN>/sendMessage?chat_id=-469322015&text="),
printLogs: true,
),

]);
Catcher(MyApp(), debugConfig: debugOptions, releaseConfig: releaseOptions);

一切都很好,但我必须将错误消息输入此参数/sendMessage?chat_id=-469322015&text="Here Error Message"

请帮我怎么做

通过创建自己的ReportMode 解决

class SilentReportMode extends ReportMode {
@override
void requestAction(Report report, BuildContext context) {
// no action needed, request is automatically accepted
print("HEREEEEE ======= ${report.error}");
try {
sendError(report);
} catch (e) {
}
super.onActionConfirmed(report);
}
Future sendError(Report report) async {
try {
Response response = await Dio().post('https://api.telegram.org/bot<TOKEN>/sendMessage?chat_id=-469322015&text=message: $report',
);
print("RESPONSE TELEGErammmmm ====== ${response.data}");
} catch (e) {
throw e;
}
}
@override
List<PlatformType> getSupportedPlatforms() =>
[PlatformType.Web, PlatformType.Android, PlatformType.iOS];
}

相关内容

最新更新