Skip to content

Instantly share code, notes, and snippets.

@sugaith
Created April 28, 2026 00:48
Show Gist options
  • Select an option

  • Save sugaith/8a8d10eb03c49431b60cd71e4262021e to your computer and use it in GitHub Desktop.

Select an option

Save sugaith/8a8d10eb03c49431b60cd71e4262021e to your computer and use it in GitHub Desktop.
Send/trigger notificaion to FCM token
#!/usr/bin/env bash
set -euo pipefail
# Simple helper script to trigger an Android inbound call test via FCM HTTP v1.
# You can override these via environment variables if needed.
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
FCM_PROJECT_ID="${FCM_PROJECT_ID:-conquer-mobile-59171}"
# Your Android device token; override with ANDROID_FCM_TOKEN if needed.
ANDROID_FCM_TOKEN="${ANDROID_FCM_TOKEN:-THE_TOKEN}"
# Firebase service account JSON: place service-account.json next to this script,
# or set SERVICE_ACCOUNT_JSON_FILE to an absolute path.
SERVICE_ACCOUNT_JSON_FILE="${SERVICE_ACCOUNT_JSON_FILE:-$SCRIPT_DIR/service-account.json}"
if [ ! -f "$SERVICE_ACCOUNT_JSON_FILE" ]; then1
echo "Service account JSON not found: $SERVICE_ACCOUNT_JSON_FILE" >&2
echo "Add that file next to the script or set SERVICE_ACCOUNT_JSON_FILE." >&2
exit 1
fi
if [ ! -r "$SERVICE_ACCOUNT_JSON_FILE" ]; then
echo "Service account JSON is not readable: $SERVICE_ACCOUNT_JSON_FILE" >&2
exit 1
fi
export GOOGLE_APPLICATION_CREDENTIALS="$SERVICE_ACCOUNT_JSON_FILE"
WORK_DIR="$HOME/fcm-http-v1"
mkdir -p "$WORK_DIR"
cd "$WORK_DIR"
# Ensure google-auth-library is available (only installs on first run).
if [ ! -d "node_modules/google-auth-library" ]; then
npm init -y >/dev/null 2>&1 || true
npm i google-auth-library@9 --silent
fi
ACCESS_TOKEN=$(
node << 'EOF'
const { GoogleAuth } = require('google-auth-library');
(async () => {
try {
const auth = new GoogleAuth({
keyFilename: process.env.GOOGLE_APPLICATION_CREDENTIALS,
scopes: ['https://www.googleapis.com/auth/firebase.messaging'],
});
const client = await auth.getClient();
const token = await client.getAccessToken();
process.stdout.write(token.token || token);
} catch (err) {
console.error('Failed to get access token:', err);
process.exit(1);
}
})();
EOF
)
if [ -z "$ACCESS_TOKEN" ]; then
echo "ACCESS_TOKEN is empty; aborting." >&2
exit 1
fi
DATA_PAYLOAD=$(cat <<EOF
{
"message": {
"token": "$ANDROID_FCM_TOKEN",
"android": {
"priority": "high",
"direct_boot_ok": true
},
"data": {
"aid": "00DfL00000OFRbZUAX",
"uid": "005fL000005WBiDQAW",
"inboundOid": "00QfL000006lzPZUAY",
"connectNumber": "+19096801177",
"displayName": "Test Inbound Call (Android)",
"phoneNumber": "+19096801177",
"companyName": "Conquer Widgets Inc.",
"offerTimeoutSeconds": "45"
}
}
}
EOF
)
echo "Sending FCM HTTP v1 data message to project '$FCM_PROJECT_ID'..."
curl -X POST \
-H "Authorization: Bearer $ACCESS_TOKEN" \
-H "Content-Type: application/json; UTF-8" \
"https://fcm.googleapis.com/v1/projects/$FCM_PROJECT_ID/messages:send" \
-d "$DATA_PAYLOAD"
echo
echo "Done."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment