-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
119 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
# syntax=docker/dockerfile:experimental | ||
|
||
# Use the Alpine Linux 3 base image | ||
FROM docker.io/alpine:3.20.0 | ||
|
||
# Define build arguments | ||
ARG TARGETPLATFORM | ||
ARG TARGETARCH | ||
ARG TARGETOS | ||
|
||
# Set the maintainer label | ||
LABEL xyz.glants.image.target_platform=$TARGETPLATFORM | ||
LABEL xyz.glants.image.target_architecture=$TARGETARCH | ||
LABEL xyz.glants.image.target_os=$TARGETOS | ||
LABEL org.opencontainers.image.title="gammu-telegram" | ||
LABEL org.opencontainers.image.source="https://github.com/gammu/gammu" | ||
|
||
RUN apk add --update --no-cache python3 py3-requests bash gammu-smsd envsubst && \ | ||
rm -rf /var/cache/apk/* | ||
|
||
ADD --chown=nobody:nobody ./scripts /scripts | ||
ADD --chown=nobody:nobody ./entrypoint.sh /entrypoint.sh | ||
RUN mkdir /data | ||
RUN chown nobody:nobody /data | ||
|
||
RUN mkdir /app | ||
RUN chown nobody:nobody /app | ||
# Set the user to nobody | ||
USER nobody | ||
|
||
ENV GAMMU_DEVICE=/dev/ttyUSB0 | ||
ENV GAMMU_CONNECTION=at | ||
|
||
ENTRYPOINT ["/entrypoint.sh"] | ||
|
||
CMD ["gammu-smsd", "-c", "/app/gammu.conf"] |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
#!/usr/bin/env python | ||
|
||
def get_latest(channel): | ||
return "v0.0.1" | ||
|
||
if __name__ == "__main__": | ||
import sys | ||
channel = sys.argv[1] | ||
print(get_latest(channel)) |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
#!/bin/bash | ||
mkdir -p /data/{inbox,outbox,sent,error} | ||
envsubst < /scripts/gammu.conf.pre \ | ||
> ~/app/gammu.conf | ||
# Run the original command | ||
exec "$@" |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
--- | ||
app: "gammu-telegram" | ||
base: false | ||
semantic_versioning: true | ||
channels: | ||
- name: "stable" | ||
platforms: | ||
- linux/arm64 | ||
- linux/amd64 | ||
stable: true | ||
tests: | ||
enabled: false |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
[gammu] | ||
device = ${GAMMU_DEVICE} | ||
connection = ${GAMMU_CONNECTION} | ||
|
||
[smsd] | ||
Service = files | ||
PIN = XXXX | ||
LogFile = /dev/stdout | ||
HangupCalls = 1 | ||
RunOnReceive = /usr/bin/python3 /scripts/sms_received.py | ||
InboxPath = /data/inbox/ | ||
OutboxPath = /data/outbox/ | ||
SentSMSPath = /data/sent/ | ||
ErrorSMSPath = /data/error/ | ||
debuglevel = 1 | ||
InboxFormat = unicode | ||
OutboxFormat = unicode | ||
TransmitFormat = auto | ||
DeliveryReport = sms | ||
DeliveryReportDelay = 7200 | ||
CheckSecurity = 0 |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
# Receive messages from GSM modem via Gammu to Telegram | ||
# https://github.com/captainmarshin/phone/ | ||
# | ||
#!/usr/bin/env python | ||
|
||
import os | ||
import sys | ||
import requests | ||
from urllib.parse import quote | ||
numparts = int(os.environ["DECODED_PARTS"]) | ||
phone = os.environ["GAMMU_NUMBER"] | ||
sender = str(os.environ["SMS_1_NUMBER"]) | ||
botkey = os.environ["TELEGRAM_BOTKEY"] | ||
chatid = os.environ["TELEGRAM_CHATID"] | ||
text = "" | ||
|
||
if numparts == 0: | ||
text = os.environ["SMS_1_TEXT"] | ||
else: | ||
for i in range(1, numparts + 1): | ||
varname = "DECODED_%d_TEXT" % i | ||
if varname in os.environ: | ||
text = text + os.environ[varname] | ||
text = text.replace("<#>", "") | ||
# Construct the Telegram message with HTML formatting | ||
html_formatted_message = "<b>{}</b>\n{} <b>({}</b>)".format(phone, text, sender) | ||
encoded_message = quote(html_formatted_message, safe='') | ||
headers = { "Accept": "application/json", "Content-Type": "application/json" } | ||
# Construct the Telegram API URL with the properly formatted message | ||
chat = "https://api.telegram.org/bot{}/sendMessage?chat_id={}&text={}&parse_mode=HTML".format(botkey, chatid, encoded_message) | ||
# Save the chat_url to a log file | ||
log_filename = "/dev/stdout" | ||
with open(log_filename, "a") as log_file: | ||
log_file.write(chat + "\n") | ||
notify = requests.get(chat, headers = headers) |