Created
March 10, 2019 19:32
-
-
Save livelace/1f778b62a418cc834af75ec176585e7e to your computer and use it in GitHub Desktop.
A bridge between smsd and mattermost.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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