Skip to content

Instantly share code, notes, and snippets.

@curso007
Forked from chusiang/teams-chat-post-for-workflows.sh
Created March 23, 2020 07:27
Show Gist options
  • Save curso007/f7dc95d1c66d55a35320cf7187ef0ca6 to your computer and use it in GitHub Desktop.
Save curso007/f7dc95d1c66d55a35320cf7187ef0ca6 to your computer and use it in GitHub Desktop.

Revisions

  1. @chusiang chusiang revised this gist Mar 28, 2018. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion teams-chat-post.sh
    Original file line number Diff line number Diff line change
    @@ -13,7 +13,7 @@
    # Help.
    if [[ "$1" == "-h" || "$1" == "--help" ]]; then
    echo 'Usage: teams-chat-post.sh "<webhook_url>" "<title>" "<color>" "<message>"'
    exit 1
    exit 0
    fi

    # Webhook or Token.
  2. @chusiang chusiang revised this gist Mar 28, 2018. 1 changed file with 14 additions and 11 deletions.
    25 changes: 14 additions & 11 deletions teams-chat-post.sh
    Original file line number Diff line number Diff line change
    @@ -2,18 +2,21 @@
    # =============================================================================
    # Author: Chu-Siang Lai / chusiang (at) drx.tw
    # Filename: teams-chat-post.sh
    # Modified: 2018-03-28 15:38
    # Modified: 2018-03-28 15:04
    # Description: Post a message to Microsoft Teams.
    #
    # Usage: teams-chat-post.sh "<webhook_url>" "<title>" "<color>" "<message>"
    #
    # Reference:
    #
    # - https://gist.github.com/dopiaza/6449505#gistcomment-1627214
    # - https://gist.github.com/chusiang/895f6406fbf9285c58ad0a3ace13d025
    #
    # =============================================================================

    # webhook & token.
    # Help.
    if [[ "$1" == "-h" || "$1" == "--help" ]]; then
    echo 'Usage: teams-chat-post.sh "<webhook_url>" "<title>" "<color>" "<message>"'
    exit 1
    fi

    # Webhook or Token.
    WEBHOOK_URL=$1
    if [[ "${WEBHOOK_URL}" == "" ]]
    then
    @@ -22,7 +25,7 @@ then
    fi
    shift

    # title .
    # Title .
    TITLE=$1
    if [[ "${TITLE}" == "" ]]
    then
    @@ -31,7 +34,7 @@ then
    fi
    shift

    # color.
    # Color.
    COLOR=$1
    if [[ "${COLOR}" == "" ]]
    then
    @@ -40,17 +43,17 @@ then
    fi
    shift

    # text.
    # Text.
    TEXT=$*
    if [[ "${TEXT}" == "" ]]
    then
    echo "No text specified."
    exit 1
    fi

    # convert formating.
    # Convert formating.
    MESSAGE=$( echo ${TEXT} | sed 's/"/\"/g' | sed "s/'/\'/g" )
    JSON="{\"title\": \"${TITLE}\", \"themeColor\": \"${COLOR}\", \"text\": \"${MESSAGE}\" }"

    # post to slack.
    # Post to Microsoft Teams.
    curl -H "Content-Type: application/json" -d "${JSON}" "${WEBHOOK_URL}"
  3. @chusiang chusiang revised this gist Mar 28, 2018. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions teams-chat-post.sh
    Original file line number Diff line number Diff line change
    @@ -1,5 +1,5 @@
    #!/bin/sh
    # ============================================================
    # =============================================================================
    # Author: Chu-Siang Lai / chusiang (at) drx.tw
    # Filename: teams-chat-post.sh
    # Modified: 2018-03-28 15:38
    @@ -11,7 +11,7 @@
    #
    # - https://gist.github.com/dopiaza/6449505#gistcomment-1627214
    #
    # ============================================================
    # =============================================================================

    # webhook & token.
    WEBHOOK_URL=$1
  4. @chusiang chusiang revised this gist Mar 28, 2018. 1 changed file with 9 additions and 9 deletions.
    18 changes: 9 additions & 9 deletions teams-chat-post.sh
    Original file line number Diff line number Diff line change
    @@ -1,8 +1,8 @@
    #!/bin/bash
    #!/bin/sh
    # ============================================================
    # Author: Chu-Siang Lai / chusiang (at) drx.tw
    # Filename: teams-chat-post.sh
    # Modified: 2018-03-28 15:04
    # Modified: 2018-03-28 15:38
    # Description: Post a message to Microsoft Teams.
    #
    # Usage: teams-chat-post.sh "<webhook_url>" "<title>" "<color>" "<message>"
    @@ -15,7 +15,7 @@

    # webhook & token.
    WEBHOOK_URL=$1
    if [[ $WEBHOOK_URL == "" ]]
    if [[ "${WEBHOOK_URL}" == "" ]]
    then
    echo "No webhook_url specified."
    exit 1
    @@ -24,7 +24,7 @@ shift

    # title .
    TITLE=$1
    if [[ $TITLE == "" ]]
    if [[ "${TITLE}" == "" ]]
    then
    echo "No title specified."
    exit 1
    @@ -33,7 +33,7 @@ shift

    # color.
    COLOR=$1
    if [[ $COLOR == "" ]]
    if [[ "${COLOR}" == "" ]]
    then
    echo "No status specified."
    exit 1
    @@ -42,15 +42,15 @@ shift

    # text.
    TEXT=$*
    if [[ $TEXT == "" ]]
    if [[ "${TEXT}" == "" ]]
    then
    echo "No text specified."
    exit 1
    fi

    # convert formating.
    MESSAGE=$( echo $TEXT | sed 's/"/\"/g' | sed "s/'/\'/g" )
    JSON="{\"title\": \"$TITLE\", \"themeColor\": \"$COLOR\", \"text\": \"$MESSAGE\" }"
    MESSAGE=$( echo ${TEXT} | sed 's/"/\"/g' | sed "s/'/\'/g" )
    JSON="{\"title\": \"${TITLE}\", \"themeColor\": \"${COLOR}\", \"text\": \"${MESSAGE}\" }"

    # post to slack.
    curl -H "Content-Type: application/json" -d "$JSON" "$WEBHOOK_URL"
    curl -H "Content-Type: application/json" -d "${JSON}" "${WEBHOOK_URL}"
  5. @chusiang chusiang created this gist Mar 28, 2018.
    56 changes: 56 additions & 0 deletions teams-chat-post.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,56 @@
    #!/bin/bash
    # ============================================================
    # Author: Chu-Siang Lai / chusiang (at) drx.tw
    # Filename: teams-chat-post.sh
    # Modified: 2018-03-28 15:04
    # Description: Post a message to Microsoft Teams.
    #
    # Usage: teams-chat-post.sh "<webhook_url>" "<title>" "<color>" "<message>"
    #
    # Reference:
    #
    # - https://gist.github.com/dopiaza/6449505#gistcomment-1627214
    #
    # ============================================================

    # webhook & token.
    WEBHOOK_URL=$1
    if [[ $WEBHOOK_URL == "" ]]
    then
    echo "No webhook_url specified."
    exit 1
    fi
    shift

    # title .
    TITLE=$1
    if [[ $TITLE == "" ]]
    then
    echo "No title specified."
    exit 1
    fi
    shift

    # color.
    COLOR=$1
    if [[ $COLOR == "" ]]
    then
    echo "No status specified."
    exit 1
    fi
    shift

    # text.
    TEXT=$*
    if [[ $TEXT == "" ]]
    then
    echo "No text specified."
    exit 1
    fi

    # convert formating.
    MESSAGE=$( echo $TEXT | sed 's/"/\"/g' | sed "s/'/\'/g" )
    JSON="{\"title\": \"$TITLE\", \"themeColor\": \"$COLOR\", \"text\": \"$MESSAGE\" }"

    # post to slack.
    curl -H "Content-Type: application/json" -d "$JSON" "$WEBHOOK_URL"