Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save JamesClonk/ad0da5c798bff3ade1ba6fb61bc7c97a to your computer and use it in GitHub Desktop.

Select an option

Save JamesClonk/ad0da5c798bff3ade1ba6fb61bc7c97a to your computer and use it in GitHub Desktop.

Revisions

  1. @chusiang chusiang revised this gist Jul 22, 2024. 1 changed file with 3 additions and 3 deletions.
    6 changes: 3 additions & 3 deletions teams-chat-post-for-workflows.sh
    Original file line number Diff line number Diff line change
    @@ -2,7 +2,7 @@
    # =============================================================================
    # Author: Chu-Siang Lai / chusiang (at) drx.tw
    # Filename: teams-chat-post-for-workflows.sh
    # Modified: 2024-07-17 19:12 (UTC+08:00)
    # Modified: 2024-07-22 11:44 (UTC+08:00)
    # Description: Post a message to Microsoft Teams via "Post to a chat when a webhook request is received" workflows.
    # Reference:
    #
    @@ -56,8 +56,8 @@ if [[ "${TEXT}" == "" ]]; then
    exit 1
    fi

    # Convert formating.
    MESSAGE=$(echo ${TEXT} | sed 's/"/\"/g' | sed "s/'/\'/g")
    # Escape char: `'`, `"`, `\` .
    MESSAGE=$(echo ${TEXT} | sed "s/'/\'/g" | sed 's/"/\"/g; s/\\/\\\\/g')

    # Adaptive Cards of TextBlock - https://adaptivecards.io/explorer/TextBlock.html
    JSON="{
  2. @chusiang chusiang revised this gist Jul 17, 2024. 1 changed file with 12 additions and 11 deletions.
    23 changes: 12 additions & 11 deletions teams-chat-post.sh
    100644 → 100755
    Original file line number Diff line number Diff line change
    @@ -21,42 +21,43 @@ fi

    # Webhook or Token.
    WEBHOOK_URL=$1
    if [[ "${WEBHOOK_URL}" == "" ]]
    then
    if [[ "${WEBHOOK_URL}" == "" ]]; then
    echo "No webhook_url specified."
    exit 1
    fi
    shift

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

    # Color.
    COLOR=$1
    if [[ "${COLOR}" == "" ]]
    then
    if [[ "${COLOR}" == "" ]]; then
    echo "No status specified."
    exit 1
    fi
    shift

    # Text.
    TEXT=$*
    if [[ "${TEXT}" == "" ]]
    then
    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 Microsoft Teams.
    curl -H "Content-Type: application/json" -d "${JSON}" "${WEBHOOK_URL}"
    curl -H "Content-Type: application/json" -d "${JSON}" "${WEBHOOK_URL}"

  3. @chusiang chusiang revised this gist Jul 17, 2024. 1 changed file with 18 additions and 3 deletions.
    21 changes: 18 additions & 3 deletions teams-chat-post-for-workflows.sh
    100644 → 100755
    Original file line number Diff line number Diff line change
    @@ -2,13 +2,14 @@
    # =============================================================================
    # Author: Chu-Siang Lai / chusiang (at) drx.tw
    # Filename: teams-chat-post-for-workflows.sh
    # Modified: 2024-07-12 19:29 (UTC+08:00)
    # Modified: 2024-07-17 19:12 (UTC+08:00)
    # Description: Post a message to Microsoft Teams via "Post to a chat when a webhook request is received" workflows.
    # Reference:
    #
    # - https://gist.github.com/chusiang/895f6406fbf9285c58ad0a3ace13d025
    # - https://devblogs.microsoft.com/microsoft365dev/retirement-of-office-365-connectors-within-microsoft-teams/
    # - https://adaptivecards.io/explorer/
    # - https://adaptivecards.io/designer/
    #
    # =============================================================================

    @@ -58,6 +59,7 @@ fi
    # Convert formating.
    MESSAGE=$(echo ${TEXT} | sed 's/"/\"/g' | sed "s/'/\'/g")

    # Adaptive Cards of TextBlock - https://adaptivecards.io/explorer/TextBlock.html
    JSON="{
    \"type\": \"message\",
    \"attachments\": [
    @@ -69,8 +71,21 @@ JSON="{
    \"type\": \"AdaptiveCard\",
    \"version\": \"1.2\",
    \"body\": [
    { \"type\": \"TextBlock\", \"text\": \"${TITLE}\", \"color\": \"${COLOR}\", \"wrap\": true },
    { \"type\": \"TextBlock\", \"text\": \"${MESSAGE}\", \"color\": \"${COLOR}\", \"wrap\": true }
    {
    \"type\": \"TextBlock\",
    \"text\": \"${TITLE}\",
    \"color\": \"${COLOR}\",
    \"weight\": \"bolder\",
    \"size\": \"large\",
    \"wrap\": true
    },
    {
    \"type\": \"TextBlock\",
    \"text\": \"${MESSAGE}\",
    \"color\": \"${COLOR}\",
    \"size\": \"small\",
    \"wrap\": true
    }
    ]
    }
    }
  4. @chusiang chusiang revised this gist Jul 12, 2024. 1 changed file with 2 additions and 1 deletion.
    3 changes: 2 additions & 1 deletion teams-chat-post-for-workflows.sh
    Original file line number Diff line number Diff line change
    @@ -2,12 +2,13 @@
    # =============================================================================
    # Author: Chu-Siang Lai / chusiang (at) drx.tw
    # Filename: teams-chat-post-for-workflows.sh
    # Modified: 2024-07-12 18:46 (UTC+08:00)
    # Modified: 2024-07-12 19:29 (UTC+08:00)
    # Description: Post a message to Microsoft Teams via "Post to a chat when a webhook request is received" workflows.
    # Reference:
    #
    # - https://gist.github.com/chusiang/895f6406fbf9285c58ad0a3ace13d025
    # - https://devblogs.microsoft.com/microsoft365dev/retirement-of-office-365-connectors-within-microsoft-teams/
    # - https://adaptivecards.io/explorer/
    #
    # =============================================================================

  5. @chusiang chusiang revised this gist Jul 12, 2024. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions teams-chat-post-for-workflows.sh
    Original file line number Diff line number Diff line change
    @@ -68,8 +68,8 @@ JSON="{
    \"type\": \"AdaptiveCard\",
    \"version\": \"1.2\",
    \"body\": [
    { \"type\": \"TextBlock\", \"text\": \"${TITLE}\", \"color\": \"${COLOR}\", \"warp\": true },
    { \"type\": \"TextBlock\", \"text\": \"${MESSAGE}\", \"color\": \"${COLOR}\", \"warp\": true }
    { \"type\": \"TextBlock\", \"text\": \"${TITLE}\", \"color\": \"${COLOR}\", \"wrap\": true },
    { \"type\": \"TextBlock\", \"text\": \"${MESSAGE}\", \"color\": \"${COLOR}\", \"wrap\": true }
    ]
    }
    }
  6. @chusiang chusiang revised this gist Jul 12, 2024. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion teams-chat-post-for-workflows.sh
    Original file line number Diff line number Diff line change
    @@ -3,7 +3,7 @@
    # Author: Chu-Siang Lai / chusiang (at) drx.tw
    # Filename: teams-chat-post-for-workflows.sh
    # Modified: 2024-07-12 18:46 (UTC+08:00)
    # Description: Post a message to Microsoft Teams via Power Automate workflows mode.
    # Description: Post a message to Microsoft Teams via "Post to a chat when a webhook request is received" workflows.
    # Reference:
    #
    # - https://gist.github.com/chusiang/895f6406fbf9285c58ad0a3ace13d025
  7. @chusiang chusiang revised this gist Jul 12, 2024. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions teams-chat-post-for-workflows.sh
    Original file line number Diff line number Diff line change
    @@ -68,8 +68,8 @@ JSON="{
    \"type\": \"AdaptiveCard\",
    \"version\": \"1.2\",
    \"body\": [
    { \"type\": \"TextBlock\", \"text\": \"${TITLE}\", \"color\": \"Light\", \"warp\": true },
    { \"type\": \"TextBlock\", \"text\": \"${MESSAGE}\", \"warp\": true }
    { \"type\": \"TextBlock\", \"text\": \"${TITLE}\", \"color\": \"${COLOR}\", \"warp\": true },
    { \"type\": \"TextBlock\", \"text\": \"${MESSAGE}\", \"color\": \"${COLOR}\", \"warp\": true }
    ]
    }
    }
  8. @chusiang chusiang revised this gist Jul 12, 2024. 1 changed file with 84 additions and 0 deletions.
    84 changes: 84 additions & 0 deletions teams-chat-post-for-workflows.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,84 @@
    #!/bin/bash
    # =============================================================================
    # Author: Chu-Siang Lai / chusiang (at) drx.tw
    # Filename: teams-chat-post-for-workflows.sh
    # Modified: 2024-07-12 18:46 (UTC+08:00)
    # Description: Post a message to Microsoft Teams via Power Automate workflows mode.
    # Reference:
    #
    # - https://gist.github.com/chusiang/895f6406fbf9285c58ad0a3ace13d025
    # - https://devblogs.microsoft.com/microsoft365dev/retirement-of-office-365-connectors-within-microsoft-teams/
    #
    # =============================================================================

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

    # Webhook or 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

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

    # Convert formating.
    MESSAGE=$(echo ${TEXT} | sed 's/"/\"/g' | sed "s/'/\'/g")

    JSON="{
    \"type\": \"message\",
    \"attachments\": [
    {
    \"contentType\": \"application/vnd.microsoft.card.adaptive\",
    \"contentUrl\": null,
    \"content\": {
    \"$schema\": \"http://adaptivecards.io/schemas/adaptive-card.json\",
    \"type\": \"AdaptiveCard\",
    \"version\": \"1.2\",
    \"body\": [
    { \"type\": \"TextBlock\", \"text\": \"${TITLE}\", \"color\": \"Light\", \"warp\": true },
    { \"type\": \"TextBlock\", \"text\": \"${MESSAGE}\", \"warp\": true }
    ]
    }
    }
    ]
    }"

    # Post to Microsoft Teams via curl.
    curl \
    --header "Content-Type: application/json" \
    --request POST \
    --data "${JSON}" \
    "${WEBHOOK_URL}"
  9. @chusiang chusiang revised this gist Jul 12, 2024. 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
    @@ -2,7 +2,7 @@
    # =============================================================================
    # Author: Chu-Siang Lai / chusiang (at) drx.tw
    # Filename: teams-chat-post.sh
    # Modified: 2024-07-09 15:15
    # Modified: 2024-07-12 18:49 (UTC+08:00)
    # Description: Post a message to Microsoft Teams via connectors, not support
    # Power Automate workflows.
    # Reference:
  10. @chusiang chusiang revised this gist Jul 12, 2024. 1 changed file with 1 addition and 0 deletions.
    1 change: 1 addition & 0 deletions teams-chat-post.sh
    Original file line number Diff line number Diff line change
    @@ -9,6 +9,7 @@
    #
    # - https://gist.github.com/chusiang/895f6406fbf9285c58ad0a3ace13d025
    # - https://devblogs.microsoft.com/microsoft365dev/retirement-of-office-365-connectors-within-microsoft-teams/
    # - Fixed for workflows edition: https://gist.github.com/chusiang/895f6406fbf9285c58ad0a3ace13d025?permalink_comment_id=5119162#gistcomment-5119162
    #
    # =============================================================================

  11. @chusiang chusiang revised this gist Jul 9, 2024. 1 changed file with 4 additions and 2 deletions.
    6 changes: 4 additions & 2 deletions teams-chat-post.sh
    Original file line number Diff line number Diff line change
    @@ -2,11 +2,13 @@
    # =============================================================================
    # Author: Chu-Siang Lai / chusiang (at) drx.tw
    # Filename: teams-chat-post.sh
    # Modified: 2021-10-18 00:09
    # Description: Post a message to Microsoft Teams.
    # Modified: 2024-07-09 15:15
    # Description: Post a message to Microsoft Teams via connectors, not support
    # Power Automate workflows.
    # Reference:
    #
    # - https://gist.github.com/chusiang/895f6406fbf9285c58ad0a3ace13d025
    # - https://devblogs.microsoft.com/microsoft365dev/retirement-of-office-365-connectors-within-microsoft-teams/
    #
    # =============================================================================

  12. @chusiang chusiang revised this gist Jul 9, 2024. No changes.
  13. @chusiang chusiang revised this gist Oct 17, 2021. 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,8 +1,8 @@
    #!/bin/sh
    #!/bin/bash
    # =============================================================================
    # Author: Chu-Siang Lai / chusiang (at) drx.tw
    # Filename: teams-chat-post.sh
    # Modified: 2018-03-28 15:04
    # Modified: 2021-10-18 00:09
    # Description: Post a message to Microsoft Teams.
    # Reference:
    #
  14. @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.
  15. @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}"
  16. @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
  17. @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}"
  18. @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"