@@ -130,6 +130,54 @@ jobs:
130130 fi
131131
132132 echo "Command completed successfully!"
133+
134+ - name : Notify Chatwoot
135+ if : success()
136+ env :
137+ CHATWOOT_URL : ${{ vars.CHATWOOT_URL }}
138+ CHATWOOT_INBOX_TOKEN : ${{ secrets.CHATWOOT_INBOX_TOKEN }}
139+ CHATWOOT_EMAIL : ${{ vars.CHATWOOT_EMAIL }}
140+ run : |
141+ # 1. Create/Identify a contact to get a source_id
142+ CONTACT_RESP=$(curl -s -X POST "${CHATWOOT_URL}/public/api/v1/inboxes/${CHATWOOT_INBOX_TOKEN}/contacts" \
143+ -H "Content-Type: application/json" \
144+ -d "{\"name\": \"GHA Deploy Bot\", \"email\": \"${CHATWOOT_EMAIL}\", \"custom_attributes\": {\"repo\": \"${{ github.repository }}\"}}")
145+
146+ SOURCE_ID=$(echo $CONTACT_RESP | jq -r '.source_id')
147+
148+ if [ -z "$SOURCE_ID" ] || [ "$SOURCE_ID" == "null" ]; then
149+ echo "Error: Failed to get Chatwoot Source ID. Response: $CONTACT_RESP"
150+ exit 0 # Don't fail the whole deploy for a notification error
151+ fi
152+
153+ # 2. Create or find a conversation
154+ CONV_RESP=$(curl -s -X POST "${CHATWOOT_URL}/public/api/v1/inboxes/${CHATWOOT_INBOX_TOKEN}/contacts/${SOURCE_ID}/conversations" \
155+ -H "Content-Type: application/json")
156+
157+ CONV_ID=$(echo $CONV_RESP | jq -r '.id')
158+
159+ if [ -z "$CONV_ID" ] || [ "$CONV_ID" == "null" ]; then
160+ # Try to see if there is an existing conversation
161+ CONV_ID=$(echo $CONV_RESP | jq -r '.[0].id')
162+ fi
163+
164+ if [ -z "$CONV_ID" ] || [ "$CONV_ID" == "null" ]; then
165+ echo "Error: Failed to get Chatwoot Conversation ID. Response: $CONV_RESP"
166+ exit 0
167+ fi
168+
169+ # 3. Send the success message
170+ MESSAGE="🚀 *Deployment Success!*
171+ *Project:* Docmost
172+ *Repository:* ${{ github.repository }}
173+ *Version:* ${{ github.event.inputs.version }}
174+ *Trigger:* Manual Deploy"
175+
176+ curl -s -X POST "${CHATWOOT_URL}/public/api/v1/inboxes/${CHATWOOT_INBOX_TOKEN}/contacts/${SOURCE_ID}/conversations/${CONV_ID}/messages" \
177+ -H "Content-Type: application/json" \
178+ -d "{\"content\": \"$MESSAGE\"}"
179+
180+ echo "Chatwoot notification sent!"
133181
134182 - name : Cleanup AWS credentials
135183 if : always()
0 commit comments