Slack Webhook Notifications

Integrations Asterisk 18+ -- Last reviewed 2026-03-29 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 ID and which DID was dialed. Uses a Gosub subroutine so any inbound context 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

No notes yet. Be the first to contribute a tip or example.

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