Skip to content

Instantly share code, notes, and snippets.

@gh640
Created April 25, 2021 06:39
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gh640/196fdc8fa67de62c36e8037bc30565a4 to your computer and use it in GitHub Desktop.
Save gh640/196fdc8fa67de62c36e8037bc30565a4 to your computer and use it in GitHub Desktop.
Sample: Send a message on Google Chat with Node `axios`
const axios = require(`axios`)
// Pass incoming webhook URL with environment variable `WEBHOOK_URL`.
const WEBHOOK_URL = process.env.WEBHOOK_URL
const title = `Hi`
const subtitle = `Hello`
const paragraph = `Hasta La Vista, Baby.`
const widget = { textParagraph: { text: paragraph } }
axios.post(WEBHOOK_URL, {
cards: [
{
header: {
title: title,
subtitle, subtitle,
},
sections: [
{
widgets: [widget],
},
],
},
],
})
.then((res) => {
console.log(res)
})
.catch((err) => {
console.error(err.toJSON())
})
const axios = require(`axios`)
// Pass incoming webhook URL with environment variable `WEBHOOK_URL`.
const WEBHOOK_URL = process.env.WEBHOOK_URL
const text = `Hello`
axios.post(WEBHOOK_URL, {
text: text,
})
.then((res) => {
console.log(res)
})
.catch((err) => {
console.error(err.toJSON())
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment