-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathwrite_tchap_message.sh
More file actions
executable file
·38 lines (30 loc) · 1.2 KB
/
write_tchap_message.sh
File metadata and controls
executable file
·38 lines (30 loc) · 1.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#!/bin/bash
set -e
# Configuration
PROJECT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
cd $PROJECT_DIR
# Load environment variables from .env file
export $(grep -v '^#' .env | xargs)
# Sending message's time management
MX_TXN="`date "+%s"`$(( RANDOM % 9999 ))"
# Message to send
BODY=$1
# Sending message's formatting
FORMATTED_BODY=$(echo "$BODY" | sed -e 's/\*\*\([^*]*\)\*\*/<strong>\1<\/strong>/g' \
-e 's/^#### \(.*\)/<h4>\1<\/h4>/' \
-e 's/^### \(.*\)/<h3>\1<\/h3>/' \
-e 's/^## \(.*\)/<h2>\1<\/h2>/' \
-e 's/^# \(.*\)/<h1>\1<\/h1>/' \
-e 's/^- \(.*\)/<li>\1<\/li>/' )
# Request for sending the message avec formatage
curl -X PUT \
--header 'Content-Type: application/json' \
--header 'Accept: application/json' \
--header "Authorization: Bearer $TCHAP_ACCOUNT_TOKEN" \
-d "{
\"msgtype\": \"m.text\",
\"body\": \"$BODY\",
\"format\": \"org.matrix.custom.html\",
\"formatted_body\": \"$FORMATTED_BODY\"
}" \
"$TCHAP_SERVER/_matrix/client/v3/rooms/$TCHAP_ROOM_TOKEN/send/m.room.message/$MX_TXN"