Compare commits

..

5 Commits

Author SHA1 Message Date
Jorge Alberto Díaz Orozco (Akiel) 3747b90846 Create dependabot.yml 2026-03-23 23:17:20 +01:00
Jorge Alberto Díaz Orozco (Akiel) b88d4128c7 Merge pull request #3 from jadolg/update-credentials-settings 2026-03-23 22:07:04 +00:00
Jorge Alberto Díaz Orozco (Akiel) 96b6b24841 Better handle errors on the new version 2026-03-23 23:06:05 +01:00
Jorge Alberto Díaz Orozco (Akiel) c551865cfd Use access tokens instead of userand password 2026-03-23 22:57:43 +01:00
Jorge Alberto Díaz Orozco (Akiel) d9187e3d33 Update version in readme 2026-03-23 21:35:08 +01:00
5 changed files with 51 additions and 59 deletions
+6
View File
@@ -0,0 +1,6 @@
version: 2
updates:
- package-ecosystem: "github-actions"
directory: "/" # Location of package manifests
schedule:
interval: "monthly"
+2 -2
View File
@@ -14,7 +14,7 @@ jobs:
uses: ./
with:
server: ${{ secrets.ROCKETCHAT_SERVER }}
user: ${{ secrets.ROCKETCHAT_USER }}
password: ${{ secrets.ROCKETCHAT_PASSWORD }}
auth-token: ${{ secrets.ROCKETCHAT_AUTH_TOKEN }}
user-id: ${{ secrets.ROCKETCHAT_USER_ID }}
channel: "#test-notifications-akiel"
message: "Test plain message from ${{ github.repository }}@${{ github.sha }}"
+12 -11
View File
@@ -1,16 +1,17 @@
# Rocket.Chat notifications GitHub action
This action will write a message on your rocket.chat server using credentials instead of a webhook.
This action sends a message to a Rocket.Chat server using a personal access token.
Read <https://docs.rocket.chat/docs/manage-personal-access-tokens> to obtain a new access token.
## Inputs
### `user`
### `auth-token`
**Required** The username to login to your rocket.chat server.
**Required** Personal access token for your Rocket.Chat server.
### `password`
### `user-id`
**Required** The password to login to your rocket.chat server.
**Required** User ID associated with the personal access token.
### `message`
@@ -39,12 +40,12 @@ jobs:
- name: Push notification to rocket.chat if the job failed
id: error-notification
if: ${{ failure() }}
uses: jadolg/rocketchat-notification-action@v1.0.1
uses: jadolg/rocketchat-notification-action@v3.0.0
with:
server: ${{ secrets.ROCKETCHAT_SERVER }}
message: Wooops! Looks like something went wrong!
user: ${{ secrets.ROCKETCHAT_USER }}
password: ${{ secrets.ROCKETCHAT_PASSWORD }}
auth-token: ${{ secrets.ROCKETCHAT_AUTH_TOKEN }}
user-id: ${{ secrets.ROCKETCHAT_USER_ID }}
channel: alerts
```
@@ -63,10 +64,10 @@ jobs:
steps:
- name: Push notification when a Pull Request is created
uses: jadolg/rocketchat-notification-action@v1.0.1
uses: jadolg/rocketchat-notification-action@v3.0.0
with:
message: Woop! Woop! A new Pull Request has being created at ${{ github.event.pull_request.html_url }}
user: ${{ secrets.ROCKETCHAT_USER }}
password: ${{ secrets.ROCKETCHAT_PASSWORD }}
auth-token: ${{ secrets.ROCKETCHAT_AUTH_TOKEN }}
user-id: ${{ secrets.ROCKETCHAT_USER_ID }}
channel: python_rocketchat_api
```
+7 -9
View File
@@ -1,15 +1,14 @@
name: "Rocket.Chat notification with credentials"
name: "Rocket.Chat notification"
description: "Send a message to Rocket.Chat"
branding:
icon: "bell"
color: "red"
inputs:
user:
description: "The username to login to your rocket.chat server"
auth-token:
description: "Personal access token for your rocket.chat server"
required: true
default: ""
password:
description: "The password to login to your rocket.chat server"
user-id:
description: "User ID associated with the personal access token"
required: true
message:
description: "The message you want to send"
@@ -29,9 +28,8 @@ runs:
shell: bash
run: ${{ github.action_path }}/entrypoint.sh
env:
INPUT_USER: ${{ inputs.user }}
INPUT_PASSWORD: ${{ inputs.password }}
INPUT_AUTH_TOKEN: ${{ inputs.auth-token }}
INPUT_USER_ID: ${{ inputs.user-id }}
INPUT_MESSAGE: ${{ inputs.message }}
INPUT_SERVER: ${{ inputs.server }}
INPUT_CHANNEL: ${{ inputs.channel }}
INPUT_CODE: ${{ inputs.code }}
+24 -37
View File
@@ -7,40 +7,33 @@ BOLD='\033[1m'
RESET='\033[0m'
SERVER="${INPUT_SERVER}"
USER="${INPUT_USER}"
PASSWORD="${INPUT_PASSWORD}"
AUTH_TOKEN="${INPUT_AUTH_TOKEN}"
USER_ID="${INPUT_USER_ID}"
MESSAGE="${INPUT_MESSAGE}"
CHANNEL="${INPUT_CHANNEL}"
LOGIN_RESPONSE=$(curl -s -X POST \
-H "Content-Type: application/json" \
-d "$(jq -n --arg user "$USER" --arg password "$PASSWORD" '{"user": $user, "password": $password}')" \
"${SERVER}/api/v1/login")
mapfile -t login_data < <(jq -r '.data.authToken, .data.userId' <<< "$LOGIN_RESPONSE")
AUTH_TOKEN="${login_data[0]}"
USER_ID="${login_data[1]}"
if [ -z "$AUTH_TOKEN" ] || [ "$AUTH_TOKEN" = "null" ]; then
LOGIN_ERROR=$(jq -r '.message // "unknown error"' <<< "$LOGIN_RESPONSE")
echo -e "${RED}${BOLD}✗ Login failed${RESET}${LOGIN_ERROR}"
exit 1
fi
echo -e "${GREEN}✓ Logged in${RESET}${USER}@${SERVER}"
RESPONSE=$(curl -s -X POST \
HTTP_CODE=$(curl -s -o /tmp/rc_response -w "%{http_code}" -X POST \
-H "Content-Type: application/json" \
-H "X-Auth-Token: ${AUTH_TOKEN}" \
-H "X-User-Id: ${USER_ID}" \
-d "$(jq -n --arg channel "$CHANNEL" --arg text "$MESSAGE" '{"channel": $channel, "text": $text}')" \
"${SERVER}/api/v1/chat.postMessage")
"${SERVER}/api/v1/chat.postMessage") || {
echo -e "${RED}${BOLD}✗ Connection failed${RESET} — could not reach ${SERVER}"
exit 1
}
RESPONSE=$(cat /tmp/rc_response)
mapfile -t response_data < <(jq -r '.success, .channel, .message.u.username, .message._id' <<< "$RESPONSE")
SUCCESS="${response_data[0]}"
CHANNEL_NAME="${response_data[1]}"
SENDER="${response_data[2]}"
MSG_ID="${response_data[3]}"
if [ "$HTTP_CODE" = "401" ]; then
echo -e "${RED}${BOLD}✗ Authentication failed${RESET} — invalid auth-token or user-id"
exit 1
fi
if ! jq -e '.success' <<< "$RESPONSE" > /dev/null 2>&1; then
echo -e "${RED}${BOLD}✗ Unexpected response${RESET} (HTTP ${HTTP_CODE})"
exit 1
fi
SUCCESS=$(jq -r '.success' <<< "$RESPONSE")
if [ "$SUCCESS" != "true" ]; then
ERROR=$(jq -r '.error // .message // "unknown error"' <<< "$RESPONSE")
@@ -48,15 +41,9 @@ if [ "$SUCCESS" != "true" ]; then
exit 1
fi
mapfile -t response_data < <(jq -r '.channel, .message.u.username, .message._id' <<< "$RESPONSE")
CHANNEL_NAME="${response_data[0]}"
SENDER="${response_data[1]}"
MSG_ID="${response_data[2]}"
echo -e "${GREEN}${BOLD}✓ Message sent${RESET} — channel: ${BOLD}${CHANNEL_NAME}${RESET}, sender: ${SENDER}, id: ${MSG_ID}"
LOGOUT_STATUS=$(curl -s -o /dev/null -w "%{http_code}" -X POST \
-H "X-Auth-Token: ${AUTH_TOKEN}" \
-H "X-User-Id: ${USER_ID}" \
"${SERVER}/api/v1/logout") || true
if [ "${LOGOUT_STATUS}" = "200" ]; then
echo -e "${GREEN}✓ Logged out${RESET}"
else
echo -e "${RED}✗ Logout failed${RESET} — HTTP ${LOGOUT_STATUS}"
fi