# Script to process inbound webhook

**URL:** <https://forums.rocket.chat/t/script-to-process-inbound-webhook/13543>\
**Category:** Community Support\
**Created:** [March 10, 2022, 5:46pm UTC](https://forums.rocket.chat/t/script-to-process-inbound-webhook/13543 "2022-03-10T17:46:43Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![notsoclever](https://avatars.discourse-cdn.com/v4/letter/n/d2c977/32.png) [@notsoclever](https://forums.rocket.chat/u/notsoclever)\
**Post date:** [March 10, 2022, 5:46pm UTC](https://forums.rocket.chat/t/script-to-process-inbound-webhook/13543/1 "2022-03-10T17:46:43Z")

</div>

Just looking for some assistance on writing a script that will process the following inbound JSON into something that RC recognizes. Specifically, I want the message to come through to RC looking like this (going to use variables here so it makes sense what specifically from the JSON I’m looking for):

New Ticket: [$client\_name/$site\_name](https://www.thing.tld/tickets/%24object_id)  
  
Contact: $user\_name  
  
Subject: [$ticket.$summary](https://www.thing.tld/tickets/%24object_id)  
  
$details

I’m thinking that $details would have to have something like replace(/\<a\b[^\>]_\>(._?)\</a\>/i,"$details") to clean it up. Any help would be appreciated.

```auto
{
  "method": "POST",
  "path": "/",
  "query": {},
   "body": {
    "id": "xxxx",
    "webhook_id": "yyyy",
    "notification_id": 6,
    "escmsg_id": "1234",
    "event": "new ticket logged",
    "message": "New ticket logged for Clever Company ID:001.",
    "object_id": 10011,
    "timestamp": "2021-12-29T21:49:39.6810696Z",
    "ticket": {
      "id": 10011,
      "dateoccurred": "2021-12-29T21:48:07.437",
      "summary": "Windows Issue",
      "details": "Attachment\r\nThere is a Windows issue\r\n\r\nAttachments\r\nScreenshot_tuzj1vgh.jpeg",
      "client_name": "Clever Company",
      "site_name": "Main",
      "user_name": "Benjamin"
  }
}
}

```

---

<div class="post-metadata">

**Author:** ![dudanogueira](https://sea1.discourse-cdn.com/flex021/user_avatar/forums.rocket.chat/dudanogueira/32/2529_2.png) [@dudanogueira](https://forums.rocket.chat/u/dudanogueira)\
**Post date:** [March 10, 2022, 7:47pm UTC](https://forums.rocket.chat/t/script-to-process-inbound-webhook/13543/2 "2022-03-10T19:47:13Z")

</div>

Hi! I believe this will help you:

> <https://github.com/dudanogueira/rocket.connect/blob/master/rocket_connect/utils/asterisk2rocketchat/incoming.webhook.Rocket.Chat.js>

the resulting message will be, in Portuguese 🙃  
 ![image](https://us1.discourse-cdn.com/flex021/uploads/rocketchat/original/2X/c/cda1ae4d4d30f422e03839751ddb69ade1ad7f8b.png)

you can basically receive any kind of json payload on an incoming webhook, then hack the resulting return as you need.

Documentation for reference:

> **[Integrations](https://docs.rocket.chat/guides/administration/admin-panel/integrations#script-details)**

---

<div class="post-metadata">

**Author:** ![notsoclever](https://avatars.discourse-cdn.com/v4/letter/n/d2c977/32.png) [@notsoclever](https://forums.rocket.chat/u/notsoclever)\
**Post date:** [March 10, 2022, 10:17pm UTC](https://forums.rocket.chat/t/script-to-process-inbound-webhook/13543/3 "2022-03-10T22:17:15Z")

</div>

Yes, thank you, that’s very helpful for the formatting. The only thing it doesn’t help me determine is how to reference the second level of JSON. For example:

```auto
{
   "body": {
    "object_id": 10011,
    "ticket": {
      "id": 10011
  }
}
}

```

How would I access object\_id and id since they are levels below. request.content.body.ticket.id and request.content.body.object\_id or something like that?

---

<div class="post-metadata">

**Author:** ![notsoclever](https://avatars.discourse-cdn.com/v4/letter/n/d2c977/32.png) [@notsoclever](https://forums.rocket.chat/u/notsoclever)\
**Post date:** [March 10, 2022, 10:42pm UTC](https://forums.rocket.chat/t/script-to-process-inbound-webhook/13543/4 "2022-03-10T22:42:45Z")

</div>

Yup, my guess was right. Thanks I should have it from here!
