fetchWebhookMessage method

Future<Message> fetchWebhookMessage(
  1. Snowflake webhookId,
  2. Snowflake messageId,
  3. {required String token,
  4. Snowflake? threadId}
)

Fetch a message sent by a webhook.

Implementation

Future<Message> fetchWebhookMessage(Snowflake webhookId, Snowflake messageId, {required String token, Snowflake? threadId}) async {
  final route = HttpRoute()
    ..webhooks(id: webhookId.toString())
    ..add(HttpRoutePart(token))
    ..messages(id: messageId.toString());
  final request = BasicRequest(
    route,
    queryParameters: {if (threadId != null) 'thread_id': threadId.toString()},
    authenticated: false,
  );

  final response = await client.httpHandler.executeSafe(request);
  final channelId = Snowflake.parse((response.jsonBody as Map<String, Object?>)['channel_id']!);
  final messageManager = (client.channels[channelId] as PartialTextChannel).messages;
  final message = messageManager.parse(response.jsonBody as Map<String, Object?>);

  client.updateCacheWith(message);
  return message;
}