SELECT
  a."publicId",
  a."createdAt",
  a."telegramMessageId",
  u."telegramUserId",
  o.kind,
  o.status,
  o."sentAt"
FROM "Application" AS a
JOIN "TelegramUser" AS u ON u.id = a."userId"
JOIN "OutboxMessage" AS o ON o."applicationId" = a.id
WHERE a."createdAt" > now() - make_interval(hours => 6)
ORDER BY a."createdAt" DESC, o.kind;
