Skip to content

How a connection's service sends events

When a connection is added without a provider, the events argument of add_connection tells Auto how the service sends webhooks when someone replies to a request sent through the connection. Auto then registers its webhook URL, the address the service sends webhooks to, while a request waits there, and removes the registration when no request is waiting. Nobody copies an address or a secret, because Auto fills in both. On this page, a delivery is one webhook the service sends. These are the events a service sends to Auto, not the playbook's own events.

A delivery from the service never answers a request by itself. It makes Auto read the replies now, through the function's own replies.

When to give it

Give events only where the service's documentation gives all three:

  • a call that registers an address;
  • a call that removes that registration;
  • a way to verify each delivery with a secret that the first call takes or returns: a signature made with the secret, a token signed with it, or the secret itself in a header.

Where it lacks one, or the address or the secret can only be set in the service's own settings, leave events out. The playbook still reads the replies on a timer.

The form

yaml
events:
  destinations:
    - type: webhook
      per: subscription
      topic: '{{ with.<the argument that names what one registration covers> }}'
      subscribe:
        tool: <the tool that registers an address>
        with:
          <its argument for the address>: '{{ webhook_url }}'
          <its argument for the secret>: '{{ secret }}'
          <its argument for what the registration covers>: '{{ topic }}'
        subscribed:
          id: /<pointer to the id in its answer>
      unsubscribe:
        tool: <the tool that removes it>
        with:
          <its argument for the id>: '{{ subscription.id }}'
      verify:
        scheme: hmac
        secret: subscription
        hash: sha256
        signed_payload: '{payload}'
        signature: $request.header.<the signature's header>
        encoding: hex
      filter:
        when:
          $request.header.<a header>: [<each value that means a reply>]
        conversation: $request.body#/<pointer to the conversation>

A destination

destinations holds one destination. Its keys call one registration a subscription.

KeyRequiredWhat it is
typeYeswebhook
perYessubscription
topicYesWhat one registration covers; see topic
subscribeYesThe call that registers Auto's address; see The calls
unsubscribeYesThe call that removes the registration
renewNoThe call that extends a registration before it expires
lease_secondsNoThe most seconds a registration lasts, where the documentation states it
verifyYesHow Auto verifies a delivery; see verify
handshakeNoHow the service checks the address before it sends; see handshake
filterYesWhich deliveries mean someone replied; see filter

topic

topic is a template that renders what one registration covers, such as one conversation or one project. Requests that render the same topic share one registration. It reads:

  • with, the arguments of the tool that sent the request, as {{ with.<argument> }};
  • sent.conversation and sent.id, as the function's deliver.sent reads them.

Where one registration covers the whole account, write a text that is the same for every request.

The calls

subscribe, unsubscribe and renew each take:

KeyRequiredWhat it is
toolYesA tool of this connection: one the server lists, or for an HTTP API an operation its document declares. Where the entry gives allowed, allowed names it too
withNoThe tool's arguments, each a template

subscribe also takes subscribed, and renew may take renewed. Each key is a JSON Pointer into what the call answers:

KeyRequiredPoints to
subscribed.idYesThe id of the registration
subscribed.expires_atNoWhen the registration expires, as an RFC 3339 date-time
subscribed.secretNoThe secret, where the service makes it
renewed.expires_atNoWhen the registration expires after the renewal, as an RFC 3339 date-time

The templates of with read:

NameInWhat it is
topicEvery callWhat topic rendered
webhook_urlsubscribeThe address Auto gives the service
secretsubscribeThe secret Auto makes for the registration
subscription.idunsubscribe, renewThe id subscribed.id read
subscription.expires_atunsubscribe, renewWhen the registration expires, where it is known
lease.seconds, lease.expires_atsubscribe, renewlease_seconds, and when it ends as an RFC 3339 date-time; only with lease_seconds

Write {{ secret }} in the with of subscribe, or point subscribed.secret at the secret the service makes. Give one of the two, never both.

Where the documentation says a registration expires:

  • give subscribed.expires_at where the call answers when, as an RFC 3339 date-time, and lease_seconds otherwise;
  • give renew where the service has a call that extends a registration. Without renew, Auto registers again before the registration expires.

renew is refused without lease_seconds or subscribed.expires_at.

verify

KeyRequiredWhat it is
schemeYeshmac, standard-webhooks, bearer or jwt
secretYessubscription

Each scheme takes keys of its own:

SchemeWhere the serviceTakes
hmacsigns each delivery with the secrethash, signed_payload, signature and encoding; prefix, timestamp and id where it has them
standard-webhookssigns as the Standard Webhooks specification doesNothing more
bearersends the secret itself in a headertoken; prefix where it has one
jwtsends a JSON Web Token signed with the secret, in a headertoken and alg; prefix where it has one
KeyWhat it is
hashsha256, sha384 or sha512
signed_payloadWhat the service signs: {payload}, the body as sent, once, joined to {timestamp} or {id} where the service signs them, as in v0:{timestamp}:{payload}
signatureThe header that holds the signature, as $request.header.<name>
encodingHow the signature is written: hex or base64
prefixWhat comes before the signature or the token in its header, such as sha256=
timestamp, idThe header or the field of the body that holds each. Required where signed_payload names it
tokenThe header that holds the secret or the token, as $request.header.<name>
algHS256, HS384 or HS512

handshake

Give handshake only where the service checks the address before it sends.

KeyRequiredWhat it is
whenYesThe values that mark the checking request, written as filter.when is
challengeYesWhere that request holds the challenge
signedYestrue where that request can be verified as a delivery is; false where it comes before any secret exists
responseNoThe fields of a JSON answer, each challenge or hmac. Left out, Auto answers the challenge alone, as text

hmac answers the challenge signed with the secret, by the hash and encoding of verify. It is taken only where scheme is hmac.

filter

KeyRequiredWhat it is
whenYesWhat a delivery holds when someone replied: each header, query parameter or field with the values it may equal. Every one must match. A value is compared as text, so a field whose value is a number or true never matches
conversationNoWhere a delivery names the conversation, as the function's delivery names it in sent.conversation. With it, Auto reads only the requests that wait in that conversation. Without it, Auto reads every request that waits through the connection
subscriptionNoWhere a delivery names the registration's id. It does not narrow what Auto reads
automaticNoWhere a delivery holds something only when an app, not a person, posted the message it is about. Auto then reads nothing

Where a delivery holds a value

A header or a field of a delivery is written as a runtime expression of OpenAPI:

WrittenReads
$request.header.<name>A header
$request.query.<name>A parameter of the query
$request.body#/<pointer>A field of the JSON body, by its JSON Pointer

signature and token are read from a header alone.

What add_connection refuses

add_connection refuses events at the key that is wrong and says what it expects there. It refuses a value that looks like a secret or a key: write {{ secret }}, never a secret.