Async Contracts

Mapa atual das filas BullMQ e das operacoes assíncronas internas do servico.

Canais

integrationConnectionLifecyclenotifications.scannotifications.dispatchpush.dispatchcommunications.delivery.status_changedcommunications.message.received

Operacoes

consumeConnectionLifecycleenqueueNotificationScanenqueueNotificationDispatchenqueuePushDispatchpublishDeliveryStatusChangedpublishMessageReceived

Modelo operacional

O contrato async documenta os jobs internos que trafegam por BullMQ/Redis. Nao e um broker publico, mas serve para registrar payloads, responsabilidade e observabilidade do fluxo.

  • contact-reminders.scan: reivindica lembretes de contato vencidos
  • contact-reminders.dispatch: envia um lembrete de contato reivindicado
  • notifications.scan: identifica deliveries pendentes
  • notifications.dispatch: prepara dispatch por canal/provider
  • push.dispatch: executa envio web push

Contrato bruto

Baixar AsyncAPI YAML

asyncapi: 3.0.0
info:
  title: Communications Service Async Contracts
  version: 0.1.0
  description: Internal asynchronous contracts represented over BullMQ/Redis queues.
channels:
  integrationConnectionLifecycle:
    address: 'integration.{environment}.connections.lifecycle.v1'
    parameters:
      environment:
        enum: [staging, production]
    messages:
      connectionLifecycle:
        $ref: '#/components/messages/ConnectionLifecycle'
  notifications.scan:
    address: notifications.scan
    messages:
      queueNotificationScan:
        $ref: '#/components/messages/QueueNotificationScan'
  notifications.dispatch:
    address: notifications.dispatch
    messages:
      queueNotificationDispatch:
        $ref: '#/components/messages/QueueNotificationDispatch'
  push.dispatch:
    address: push.dispatch
    messages:
      queuePushDispatch:
        $ref: '#/components/messages/QueuePushDispatch'
  communications.delivery.status_changed:
    address: communications.delivery.status_changed
    messages:
      deliveryStatusChanged:
        $ref: '#/components/messages/DeliveryStatusChanged'
  communications.message.received:
    address: communications.message.received
    messages:
      messageReceived:
        $ref: '#/components/messages/MessageReceived'
operations:
  consumeConnectionLifecycle:
    action: receive
    channel:
      $ref: '#/channels/integrationConnectionLifecycle'
  enqueueNotificationScan:
    action: send
    channel:
      $ref: '#/channels/notifications.scan'
    messages:
      - $ref: '#/channels/notifications.scan/messages/queueNotificationScan'
  enqueueNotificationDispatch:
    action: send
    channel:
      $ref: '#/channels/notifications.dispatch'
    messages:
      - $ref: '#/channels/notifications.dispatch/messages/queueNotificationDispatch'
  enqueuePushDispatch:
    action: send
    channel:
      $ref: '#/channels/push.dispatch'
    messages:
      - $ref: '#/channels/push.dispatch/messages/queuePushDispatch'
  publishDeliveryStatusChanged:
    action: send
    channel:
      $ref: '#/channels/communications.delivery.status_changed'
    messages:
      - $ref: '#/channels/communications.delivery.status_changed/messages/deliveryStatusChanged'
  publishMessageReceived:
    action: send
    channel:
      $ref: '#/channels/communications.message.received'
    messages:
      - $ref: '#/channels/communications.message.received/messages/messageReceived'
components:
  messages:
    ConnectionLifecycle:
      contentType: application/json
      externalDocs:
        url: https://github.com/ailianbr/integration-service/blob/67c60bb9d5b37dec94ab6f6a7f4b4eab9df13ca1/docs/contracts/connection-lifecycle-v1.md
      payload:
        $ref: '#/components/schemas/ConnectionLifecycleEnvelopeV1'
    QueueNotificationScan:
      payload:
        type: object
        additionalProperties: false
    QueueNotificationDispatch:
      payload:
        type: object
        required: [deliveryId]
        properties:
          deliveryId:
            type: string
    QueuePushDispatch:
      payload:
        type: object
        required: [deliveryId]
        properties:
          deliveryId:
            type: string
    DeliveryStatusChanged:
      payload:
        type: object
        required: [event_type, subject, correlation_id, occurred_at, payload]
        properties:
          event_type:
            const: communications.delivery.status_changed
          subject:
            $ref: '#/components/schemas/CrmSubject'
          correlation_id:
            type: string
          occurred_at:
            type: string
            format: date-time
          payload:
            type: object
            required: [status, channel]
            properties:
              status:
                type: string
                enum: [queued, sent, delivered, failed, bounced, unsubscribed]
              channel:
                type: string
                enum: [email, realtime, push, whatsapp, webhook]
              provider:
                type: string
              notification_id:
                type: string
              notification_delivery_id:
                type: string
              recipient_id:
                type: string
              provider_message_id:
                type: string
              recipient:
                type: string
              error_message:
                type: string
    MessageReceived:
      payload:
        type: object
        required: [event_type, subject, correlation_id, occurred_at, payload]
        properties:
          event_type:
            const: communications.message.received
          subject:
            $ref: '#/components/schemas/CrmSubject'
          correlation_id:
            type: string
          occurred_at:
            type: string
            format: date-time
          payload:
            type: object
            required: [channel, from]
            properties:
              channel:
                const: email
              from:
                type: string
              to:
                type: string
              subject:
                type: string
              body_text:
                type: string
              body_html:
                type: string
              provider_message_id:
                type: string
              in_reply_to:
                type: string
              references:
                type: string
  schemas:
    ConnectionLifecycleEnvelopeV1:
      oneOf:
      - $ref: '#/components/schemas/LifecycleReauthorizationRequired'
      - $ref: '#/components/schemas/LifecycleNotificationRequested'
      - $ref: '#/components/schemas/LifecycleNotificationCancelled'
    LifecycleEnvelope:
      type: object
      additionalProperties: false
      required:
      - schema_version
      - event_id
      - instance_id
      - source
      - event_type
      - occurred_at
      - idempotency_key
      - payload
      properties:
        schema_version:
          const: connection-lifecycle.v1
        event_id:
          type: string
          minLength: 1
          maxLength: 64
        instance_id:
          type: string
          minLength: 1
          maxLength: 64
        source:
          const: integration-service
        event_type:
          type: string
        occurred_at:
          type: string
          format: date-time
        idempotency_key:
          type: string
          minLength: 1
          maxLength: 200
        payload:
          type: object
    LifecycleReauthorizationRequired:
      allOf:
      - $ref: '#/components/schemas/LifecycleEnvelope'
      - properties:
          event_type:
            const: connection.reauthorization_required
          payload:
            type: object
            additionalProperties: false
            required:
            - connection_id
            - connection_key
            - provider
            - auth_scheme_key
            - error_category
            properties:
              connection_id:
                type: string
                minLength: 1
                maxLength: 64
              connection_key:
                type: string
                minLength: 1
                maxLength: 128
              provider:
                type: string
                minLength: 1
                maxLength: 64
              auth_scheme_key:
                type: string
                minLength: 1
                maxLength: 128
              error_category:
                type: string
                minLength: 1
                maxLength: 64
              provider_status_code:
                type:
                - integer
                - 'null'
              provider_error_code:
                type:
                - string
                - 'null'
                maxLength: 128
    LifecycleNotificationRequested:
      allOf:
      - $ref: '#/components/schemas/LifecycleEnvelope'
      - properties:
          event_type:
            const: connection.notification.requested
          payload:
            type: object
            additionalProperties: false
            required:
            - connection_id
            - connection_key
            - connection_name
            - reconnect_path
            - provider
            - auth_scheme_key
            - notification_type
            - projected_expiry_date
            - timezone
            properties:
              connection_id:
                type: string
                minLength: 1
                maxLength: 64
              connection_name:
                type: string
                minLength: 1
                maxLength: 255
              reconnect_path:
                const: /dashboard/settings/integrations?tab=connections
              connection_key:
                type: string
                minLength: 1
                maxLength: 128
              provider:
                type: string
                minLength: 1
                maxLength: 64
              auth_scheme_key:
                type: string
                minLength: 1
                maxLength: 128
              notification_type:
                enum:
                - connection_expiring
                - connection_expiring_last_call
                - connection_expired
              projected_expiry_date:
                type: string
                format: date
              timezone:
                type: string
                minLength: 1
                maxLength: 64
    LifecycleNotificationCancelled:
      allOf:
      - $ref: '#/components/schemas/LifecycleEnvelope'
      - properties:
          event_type:
            const: connection.notification.cancelled
          payload:
            type: object
            additionalProperties: false
            required:
            - connection_id
            - provider
            - notification_type
            properties:
              connection_id:
                type: string
                minLength: 1
                maxLength: 64
              provider:
                type: string
                minLength: 1
                maxLength: 64
              notification_type:
                const: all_pending
              projected_expiry_at:
                type:
                - string
                - 'null'
                format: date-time
    CrmSubject:
      type: object
      required: [type, id]
      properties:
        type:
          type: string
        id:
          type: string