Skip to content

Instantly share code, notes, and snippets.

@livelace
Created March 10, 2019 19:32
Show Gist options
  • Save livelace/1f778b62a418cc834af75ec176585e7e to your computer and use it in GitHub Desktop.
Save livelace/1f778b62a418cc834af75ec176585e7e to your computer and use it in GitHub Desktop.
A bridge between smsd and mattermost.
#!/usr/bin/env bash
# This script acts as a bridge between smstools and mattermost.
#
# Dependencies:
# 1. curl
# 2. iconv
# 3. procmail
# Example of smsd.conf:
#
# devices = GSM1
# logfile = /var/log/smsd.log
# loglevel = 7
# incoming_utf8 = yes
# [GSM1]
# init = AT+CPMS="ME","ME","ME"
# device = /dev/ttyUSB0
# incoming = yes
# phonecalls = yes
# eventhandler = /opt/toolset/sms2mattermost.sh
export LC_ALL=ru_RU.UTF-8
MATTERMOST_HOOK="https://example.com/hooks/gtrthw7ab3y13g18ucdjd9cd4w"
case "$1" in
CALL)
FROM=`formail -zx From: <$2`
PAYLOAD="payload={\"attachments\": [{\"pretext\": \"Source: **CALL: ${FROM}**\", \"color\": \"#E40303\", \"text\": \"Missed call\"}]}"
curl -s -X POST -d "$PAYLOAD" "$MATTERMOST_HOOK"
;;
RECEIVED)
FROM=`formail -zx From: <$2`
TEXT=`formail -I "" <$2 | tr -d "\n" | iconv -f UCS-2BE -t UTF-8`
TEXT=`echo "$TEXT" | sed 's|"|\\\"|g'`
PAYLOAD="payload={\"attachments\": [{\"pretext\": \"Source: **SMS: ${FROM}**\", \"color\": \"#00C100\", \"text\": \"${TEXT}\"}]}"
curl -s -X POST -d "$PAYLOAD" "$MATTERMOST_HOOK"
;;
esac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment