Compare commits
7 Commits
master
...
dist/ubunt
Author | SHA1 | Date | |
---|---|---|---|
7b57394cdd | |||
058ec366d6 | |||
236f498ebf | |||
651471b70d | |||
64b76a843a | |||
2888a6aded | |||
296ed2b148 |
31
README.md
Normal file
31
README.md
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
# rocket-send
|
||||||
|
|
||||||
|
Simple script Bash permettant d'envoyer un message en ligne de commande sur un canal Rocket.Chat via l'API REST de celui ci.
|
||||||
|
|
||||||
|
## Utilisation
|
||||||
|
|
||||||
|
```
|
||||||
|
Envoie un message sur un canal Rocket.Chat
|
||||||
|
|
||||||
|
Usage: rocket-send -c [CHANNEL] -m [MESSAGE]
|
||||||
|
|
||||||
|
Options:
|
||||||
|
-c, --channel [Obligatoire] Nom du canal sur lequel envoyer le message
|
||||||
|
-m, --message [Obligatoire] Message à envoyer
|
||||||
|
-s, --server URL racine du serveur Rocket.Chat
|
||||||
|
-e, --emoji Emoji à utiliser comme avatar pour le message
|
||||||
|
-n, --nickname Pseudonyme à utiliser pour le message
|
||||||
|
--config-dir Chemin vers le répertoire de configuration, par défaut $HOME/.config/rocket-send
|
||||||
|
-h, --help Afficher l'aide
|
||||||
|
```
|
||||||
|
|
||||||
|
## Configuration
|
||||||
|
|
||||||
|
L'envoie d'un message sur un Rocket.Chat nécessite l'utilisation d'un compte utilisateur. Les identifiants utilisés par la commande `rocket-send` doivent être placé par défaut dans le fichier `$HOME/.config/rocket-send/config`.
|
||||||
|
|
||||||
|
Le fichier doit au minimum présenter les variables de configuration suivantes:
|
||||||
|
|
||||||
|
```shell
|
||||||
|
RC_LOGIN=<identifiant>
|
||||||
|
RC_PASSWORD=<mot de passe>
|
||||||
|
```
|
107
bin/rocket-send
Executable file
107
bin/rocket-send
Executable file
@ -0,0 +1,107 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
set -eo pipefail
|
||||||
|
|
||||||
|
RC_HOST_URL=https://rocket.cadoles.com
|
||||||
|
RC_CONFIG_DIR="$HOME/.config/rocket-send"
|
||||||
|
RC_LOGIN=
|
||||||
|
RC_PASSWORD=
|
||||||
|
RC_CLIENT_ID=
|
||||||
|
RC_CLIENT_TOKEN=
|
||||||
|
RC_MESSAGE=
|
||||||
|
RC_CHANNEL=
|
||||||
|
RC_ALIAS=
|
||||||
|
RC_EMOJI=
|
||||||
|
|
||||||
|
function help {
|
||||||
|
cat<<EOF 1>&2
|
||||||
|
Envoie un message sur un canal Rocket.Chat
|
||||||
|
|
||||||
|
Usage: rocket-send -c [CHANNEL] -m [MESSAGE]
|
||||||
|
|
||||||
|
Options:
|
||||||
|
-c, --channel [Obligatoire] Nom du canal sur lequel envoyer le message
|
||||||
|
-m, --message [Obligatoire] Message à envoyer
|
||||||
|
-s, --server URL racine du serveur Rocket.Chat
|
||||||
|
-e, --emoji Emoji à utiliser comme avatar pour le message
|
||||||
|
-a, --alias Alias à utiliser pour le message
|
||||||
|
--config-dir Chemin vers le répertoire de configuration, par défaut $HOME/.config/rocket-send
|
||||||
|
-h, --help Afficher l'aide
|
||||||
|
EOF
|
||||||
|
}
|
||||||
|
|
||||||
|
function get_options {
|
||||||
|
while [[ "$#" -gt 0 ]]
|
||||||
|
do
|
||||||
|
case $1 in
|
||||||
|
-s|--server)
|
||||||
|
RC_HOST_URL="$2"
|
||||||
|
;;
|
||||||
|
-e|--emoji)
|
||||||
|
RC_EMOJI="$2"
|
||||||
|
;;
|
||||||
|
-a|--alias)
|
||||||
|
RC_ALIAS="$2"
|
||||||
|
;;
|
||||||
|
--config-dir)
|
||||||
|
RC_CONFIG_DIR="$2"
|
||||||
|
;;
|
||||||
|
-m|--message)
|
||||||
|
RC_MESSAGE="$2"
|
||||||
|
;;
|
||||||
|
-c|--channel)
|
||||||
|
RC_CHANNEL="$2"
|
||||||
|
;;
|
||||||
|
-h|--help)
|
||||||
|
help
|
||||||
|
exit 0
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
shift
|
||||||
|
done
|
||||||
|
}
|
||||||
|
|
||||||
|
function get_config {
|
||||||
|
mkdir -p "$RC_CONFIG_DIR"
|
||||||
|
if [ -e "$RC_CONFIG_DIR/config" ]; then
|
||||||
|
source "$RC_CONFIG_DIR/config"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
function login {
|
||||||
|
local login=$1
|
||||||
|
local password=$2
|
||||||
|
|
||||||
|
local res=$(curl --silent \
|
||||||
|
-H "Content-Type:application/json" \
|
||||||
|
"$RC_HOST_URL/api/v1/login" \
|
||||||
|
-d "{ \"user\": \"$login\", \"password\": \"$password\" }" \
|
||||||
|
)
|
||||||
|
|
||||||
|
RC_CLIENT_ID=$(echo $res | jq -r '.data.userId')
|
||||||
|
RC_CLIENT_TOKEN=$(echo $res | jq -r '.data.authToken')
|
||||||
|
}
|
||||||
|
|
||||||
|
function post_message {
|
||||||
|
local channel=$1
|
||||||
|
local message=$2
|
||||||
|
local emoji=$3
|
||||||
|
local alias=$4
|
||||||
|
|
||||||
|
curl --silent \
|
||||||
|
-H "X-Auth-Token: $RC_CLIENT_TOKEN" \
|
||||||
|
-H "X-User-Id: $RC_CLIENT_ID" \
|
||||||
|
-H "Content-Type:application/json" \
|
||||||
|
"$RC_HOST_URL/api/v1/chat.postMessage" \
|
||||||
|
-d "{ \"channel\": \"$channel\", \"text\": \"$message\", \"emoji\": \"$emoji\", \"alias\": \"$alias\" }"
|
||||||
|
}
|
||||||
|
|
||||||
|
function main {
|
||||||
|
get_config
|
||||||
|
get_options "$@"
|
||||||
|
|
||||||
|
login "$RC_LOGIN" "$RC_PASSWORD"
|
||||||
|
post_message "$RC_CHANNEL" "$RC_MESSAGE" "$RC_EMOJI" "$RC_ALIAS"
|
||||||
|
}
|
||||||
|
|
||||||
|
main "$@"
|
1
debian/cadoles-rocket-send.install
vendored
Normal file
1
debian/cadoles-rocket-send.install
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
bin usr
|
1
debian/compat
vendored
Normal file
1
debian/compat
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
9
|
14
debian/control
vendored
Normal file
14
debian/control
vendored
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
Source: cadoles-rocket-send
|
||||||
|
Section: unknown
|
||||||
|
Priority: optional
|
||||||
|
Maintainer: Cadoles <contact@cadoles.com>
|
||||||
|
Build-Depends: debhelper (>= 8.0.0)
|
||||||
|
Standards-Version: 3.9.4
|
||||||
|
Homepage: http://forge.cadoles.com/Cadoles/cadoles-rocket-send
|
||||||
|
Vcs-Git: http://forge.cadoles.com/Cadoles/cadoles-rocket-send.git
|
||||||
|
Vcs-Browser: http://forge.cadoles.com/Cadoles/cadoles-rocket-send
|
||||||
|
|
||||||
|
Package: cadoles-rocket-send
|
||||||
|
Architecture: all
|
||||||
|
Depends: ${shlibs:Depends}, ${misc:Depends}, curl, jq
|
||||||
|
Description: Utilitaire d'envoi de message en ligne de commande sur un serveur Rocket.Chat
|
8
debian/rules
vendored
Normal file
8
debian/rules
vendored
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
#!/usr/bin/make -f
|
||||||
|
# -*- makefile -*-
|
||||||
|
|
||||||
|
# Uncomment this to turn on verbose mode.
|
||||||
|
export DH_VERBOSE=1
|
||||||
|
|
||||||
|
%:
|
||||||
|
dh $@
|
1
debian/source/format
vendored
Normal file
1
debian/source/format
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
3.0 (native)
|
Reference in New Issue
Block a user