pingAppservice method
This API asks the homeserver to call the
/_matrix/app/v1/ping
endpoint on the
application service to ensure that the homeserver can communicate
with the application service.
This API requires the use of an application service access token (as_token
)
instead of a typical client's access token. This API cannot be invoked by
users who are not identified as application services. Additionally, the
appservice ID in the path must be the same as the appservice whose as_token
is being used.
appserviceId
The appservice ID of the appservice to ping. This must be the same
as the appservice whose as_token
is being used to authenticate the
request.
transactionId
An optional transaction ID that is passed through to the /_matrix/app/v1/ping
call.
returns duration_ms
:
The duration in milliseconds that the
/_matrix/app/v1/ping
request took from the homeserver's point of view.
Implementation
Future<int> pingAppservice(
String appserviceId, {
String? transactionId,
}) async {
final requestUri = Uri(
path:
'_matrix/client/v1/appservice/${Uri.encodeComponent(appserviceId)}/ping',
);
final request = Request('POST', baseUri!.resolveUri(requestUri));
request.headers['authorization'] = 'Bearer ${bearerToken!}';
request.headers['content-type'] = 'application/json';
request.bodyBytes = utf8.encode(
jsonEncode({
if (transactionId != null) 'transaction_id': transactionId,
}),
);
final response = await httpClient.send(request);
final responseBody = await response.stream.toBytes();
if (response.statusCode != 200) unexpectedResponse(response, responseBody);
final responseString = utf8.decode(responseBody);
final json = jsonDecode(responseString);
return json['duration_ms'] as int;
}