how to refactor the bash script with duplicates

I have a work bash script, but I have a lot of duplicates on the body "CURL" …

if ! npm test
then
# Talk to the man about failure, if the npm output was not enough
echo> & 2 "The test failed"
curl -X POST -H Content Type: application / json & # 39; --data & # 39; {"text": "The tests failed for Platform:" $ PLATFORM "Environment": " $ ENVIRONMENT "& # 39;"} "https: //hooks.slack.com/services/rr/qq/pp

# Leave and inform computers of failure (0 = success, 1+ = failure)
echo "A test failed"
exit 1

other

echo "Successful tests"
curl -X POST -H Content Type: application / json & # 39; --data & # 39; {"text": "Successful tests for Platform:" $ PLATFORM "Environment": " $ ENVIRONMENT "& # 39;"} & # 39; https: //hooks.slack.com/services/rr/qq/pp

Fi