Slack Webhook Notifications

Integrations Asterisk 18+ -- Last reviewed 2026-08-22 integrations slack webhooks gosub security Found this useful? Upvote it. ×

Slack Webhook Notifications

Send a Slack message whenever an inbound call arrives, showing the caller IDThe calling party number (and optionally name) presented on an outbound call, set from the endpoint or manipulated in the dialplan. and which DID was dialed. Uses a Gosub subroutine so any inbound contextA named section of the dialplan that groups extensions. Calls enter a specific context and can only reach extensions visible from it, making contexts the basic unit of call routing and security. can call it with one line.

Requirements

Global Variables

[globals]
SLACK_WEBHOOK = https://hooks.slack.com/services/XXXXXXXXX/YYYYYYYYYYY/ZZZZZZZZZZZZZZZZZZZZZZZZ

Subroutine

[slack-notify]
; Sends incoming call notification to Slack
; ARG1 = destination name (e.g., "Sales", "Support")
; ARG2 = DID number (e.g., "508-555-1234")
;
; Caller ID is sanitized before passing to System() to prevent
; shell injection and JSON breakage from crafted caller ID data.
exten => s,1,Set(SAFE_NAME=${FILTER(A-Za-z0-9 .,${CALLERID(name)})})
 same => n,Set(SAFE_NUM=${FILTER(0-9+,${CALLERID(num)})})
 same => n,Set(SLACK_MSG={"text":"Incoming call to *${ARG1}* (${ARG2})\nFrom: ${SAFE_NAME} <${SAFE_NUM}>"})
 same => n,System(curl -s -X POST -H 'Content-type: application/json' --data '${SLACK_MSG}' ${SLACK_WEBHOOK} &)
 same => n,Return()

Usage in Inbound Context

[from-trunk]
exten => 15085551234,1,NoOp(Inbound to Sales DID)
 same => n,Gosub(slack-notify,s,1(Sales,508-555-1234))
 same => n,Goto(ring-sales,s,1)

How it works

  1. FILTER() for security: Caller ID name and number are attacker-controlled data. A crafted caller ID like "; rm -rf /; " would break the JSON and could execute arbitrary commands via System(). FILTER(A-Za-z0-9 .,...) strips everything except alphanumerics, spaces, and periods. FILTER(0-9+,...) keeps only digits and +.
  2. System() with background: The trailing & runs curl in the background so the call is not delayed waiting for the HTTP request to complete.
  3. Gosub/Return pattern: Unlike Macro() (deprecated), Gosub() is the recommended way to create reusable subroutines. Arguments are accessed as ${ARG1}, ${ARG2}, etc. Return() passes control back to the calling context.
  4. JSON construction: The Slack message uses Slack's mrkdwn format. *bold* for the DID name and \n for line breaks.

Tips

User Notes

Know a tip or gotcha for this topic? Share it below and help others.

Contribute a note

Share a tip, gotcha, or practical example. Keep it under 2000 characters. No questions (use the Asterisk community forums for support). Wrap code in backticks.

Moderated before publishing. Email never shown.
Related Snippets