You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

求用于Facebook Workplace消息推送的curl+bash脚本及POC实现步骤

Hey there! I’ve put together a quick POC bash script using curl and Workplace’s incoming webhooks for exactly this use case—sending system alerts to a Workplace group. Let’s break this down step by step since the setup can be easy to miss if you’re new to Workplace integrations.

First: Get Your Workplace Incoming Webhook URL

Before writing the script, you need to set up an incoming webhook in Workplace:

  • Go to the Workplace group where you want alerts to land
  • Click Group Settings → Integrations → Add Integration
  • Search for and select Incoming Webhook
  • Give your integration a name (like "System Alerts") and pick an icon if you want, then select the target group
  • Copy the generated webhook URL—keep this safe, it’s your entry point to send messages

Basic Bash Script for Alert Push

Here’s a minimal script that sends a plain text alert. Save this as send_workplace_alert.sh:

#!/bin/bash

# Replace this with your actual webhook URL
WEBHOOK_URL="https://your-workplace-webhook-url-goes-here"

# Customize this alert message (or pull it from your system's alert output)
ALERT_TEXT="⚠️ Critical Alert: High memory usage detected on server prod-db-01 (92% used)"

# Send the request with curl
curl -X POST \
  -H "Content-Type: application/json" \
  -d '{
    "text": "'"$ALERT_TEXT"'"
  }' "$WEBHOOK_URL"

Make it executable with chmod +x send_workplace_alert.sh, then run it to test—you should see the alert pop up in your Workplace group.

Advanced Version: Accept Custom Alert Details

If you want to pass dynamic alert data (like subject, server name, metrics) from your system, here’s a script that takes command-line arguments:

#!/bin/bash

# Check if we got enough arguments
if [ $# -ne 2 ]; then
    echo "Usage: $0 <alert-subject> <alert-details>"
    exit 1
fi

WEBHOOK_URL="https://your-workplace-webhook-url-goes-here"
ALERT_SUBJECT="$1"
ALERT_DETAILS="$2"

# Build a formatted message (Workplace supports basic Markdown)
FORMATTED_MESSAGE="### 🚨 $ALERT_SUBJECT\n\n**Alert Details:**\n$ALERT_DETAILS"

curl -X POST \
  -H "Content-Type: application/json" \
  -d '{
    "text": "'"$FORMATTED_MESSAGE"'"
  }' "$WEBHOOK_URL"

Use it like this:

./send_workplace_alert.sh "High CPU Utilization" "Server: prod-web-01\nCPU Usage: 96%\nTimestamp: $(date '+%Y-%m-%d %H:%M:%S')"

Key Notes

  • Security Tip: Don’t hardcode your webhook URL in the script for production. Use an environment variable instead: export WORKPLACE_WEBHOOK="your-url" then reference $WORKPLACE_WEBHOOK in the script.
  • Troubleshooting: If messages aren’t showing up, add -v to the curl command to debug the request, or check if your server has outbound access to Workplace’s domains (allow *.facebook.com in firewalls/proxies).
  • Formatting: Workplace supports basic Markdown (bold, headers, code blocks) so you can make alerts more readable—just adjust the text field in the JSON payload.

内容的提问来源于stack exchange,提问作者Jared

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.19 08:43:59