@@ -133,49 +133,25 @@ jobs:
133133
134134 - name : Notify Chatwoot
135135 if : success()
136- env :
137- CHATWOOT_URL : ${{ vars.CHATWOOT_URL }}
138- CHATWOOT_INBOX_TOKEN : ${{ secrets.CHATWOOT_INBOX_TOKEN }}
139- CHATWOOT_EMAIL : ${{ vars.CHATWOOT_EMAIL }}
140136 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
170137 MESSAGE="🚀 *Deployment Success!*
171138 *Project:* Docmost
172139 *Repository:* ${{ github.repository }}
173140 *Version:* ${{ github.event.inputs.version }}
174141 *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\"}"
142+
143+ curl --location "${{ vars.CHATWOOT_URL }}/api/v1/accounts/${{ vars.CHATWOOT_ACCOUNT_ID }}/conversations" \
144+ --header "api_access_token: ${{ secrets.CHATWOOT_ACCESS_TOKEN }}" \
145+ --header 'Content-Type: application/json' \
146+ --data "{
147+ \"source_id\": \"${{ secrets.CHATWOOT_INBOX_TOKEN }}\",
148+ \"inbox_id\": ${{ vars.CHATWOOT_INBOX_ID }},
149+ \"contact_id\": ${{ vars.CHATWOOT_CONTACT_ID }},
150+ \"message\": {
151+ \"content\": \"$MESSAGE\",
152+ \"message_type\": \"outgoing\"
153+ }
154+ }"
179155
180156 echo "Chatwoot notification sent!"
181157
0 commit comments