Webhooks

In this guide, we will look at how to register and consume webhooks to integrate your app with Oblic. With webhooks, your app can know when something happens in Oblic, such as someone sending a message or adding a contact.

Registering webhooks

To register a new webhook, you need to have a URL in your app that Oblic can call. You can configure a new webhook from the Oblic dashboard under API settings. Give your webhook a name, pick the events you want to listen for, and add your URL.

Now, whenever something of interest happens in your app, a webhook is fired off by Oblic. In the next section, we'll look at how to consume webhooks.

Consuming webhooks

When your app receives a webhook request from Oblic, check the type attribute to see what event caused it. The first part of the event type will tell you the payload type, e.g., a conversation, message, etc.

Example webhook payload

{
  "id": "a056V7R7NmNRjl70",
  "type": "conversation.updated",
  "payload": {
    "id": "WAz8eIbvDR60rouK"
    // ...
  }
}

In the example above, a conversation was updated, and the payload type is a conversation.


Event types

  • नाव
    contact.created
    वर्णन

    A new contact was created.

  • नाव
    contact.updated
    वर्णन

    An existing contact was updated.

  • नाव
    contact.deleted
    वर्णन

    A contact was successfully deleted.

  • नाव
    conversation.created
    वर्णन

    A new conversation was created.

  • नाव
    conversation.updated
    वर्णन

    An existing conversation was updated.

  • नाव
    conversation.deleted
    वर्णन

    A conversation was successfully deleted.

  • नाव
    message.created
    वर्णन

    A new message was created.

  • नाव
    message.updated
    वर्णन

    An existing message was updated.

  • नाव
    message.deleted
    वर्णन

    A message was successfully deleted.

  • नाव
    group.created
    वर्णन

    A new group was created.

  • नाव
    group.updated
    वर्णन

    An existing group was updated.

  • नाव
    group.deleted
    वर्णन

    A group was successfully deleted.

  • नाव
    attachment.created
    वर्णन

    A new attachment was created.

  • नाव
    attachment.updated
    वर्णन

    An existing attachment was updated.

  • नाव
    attachment.deleted
    वर्णन

    An attachment was successfully deleted.

Example payload

{
  "id": "a056V7R7NmNRjl70",
  "type": "message.updated",
  "payload": {
    "id": "SIuAFUNKdSYHZF2w",
    "conversation_id": "xgQQXg3hrtjh7AvZ",
    "contact": {
      "id": "WAz8eIbvDR60rouK",
      "username": "KevinMcCallister",
      "phone_number": "1-800-759-3000",
      "avatar_url": "https://assets.oblic.chat/avatars/kevin.jpg",
      "last_active_at": 705103200,
      "created_at": 692233200
    },
    "message": "I’m traveling with my dad. He’s at a meeting. I hate meetings.",
    "reactions": [],
    "attachments": [],
    "read_at": 705103200,
    "created_at": 692233200,
    "updated_at": 692233200
  }
}

Security

To know for sure that a webhook was, in fact, sent by Oblic instead of a malicious actor, you can verify the request signature. Each webhook request contains a header named x-oblic-signature, and you can verify this signature by using your secret webhook key. The signature is an HMAC hash of the request payload hashed using your secret key. Here is an example of how to verify the signature in your app:

Verifying a request

const signature = req.headers['x-oblic-signature']
const hash = crypto.createHmac('sha256', secret).update(payload).digest('hex')

if (hash === signature) {
  // Request is verified
} else {
  // Request could not be verified
}

If your generated signature matches the x-oblic-signature header, you can be sure that the request was truly coming from Oblic. It's essential to keep your secret webhook key safe — otherwise, you can no longer be sure that a given webhook was sent by Oblic. Don't commit your secret webhook key to GitHub!

हे पृष्ठ उपयुक्त होते का?

Note: This page is not yet available in your language. Showing English version.