hangouts-chat-webhook
v0.1.1
Published
Fluent api to send webhook to Hangouts chat
Downloads
445
Maintainers
Readme
hangouts-chat-webhook
Fluent api to send webhook to Hangouts chat
Installation
$ npm install --save hangouts-chat-webhook
Usage
We don't include any http client in order to let you choose your preferred one. Below is a simple example with superagent.
import * as superagent from "superagent";
import { Button, Card, CardHeader, Icon, Image, KeyValue, Message, OnClick, OpenLink, Section, TextButton, TextParagraph, WidgetMarkup } from "hangouts-chat-webhook";
const message: Message = new Message()
.addCard(new Card()
.setHeader(new CardHeader()
.setTitle("Google Chat")
.setSubtitle("Incoming Webhook")
)
.addSection(new Section()
.addWidget(new WidgetMarkup()
.setImage(new Image()
.setImageUrl("https://www.gstatic.com/images/branding/product/2x/chat_64dp.png")
)
)
.addWidget(new WidgetMarkup()
.setKeyValue(new KeyValue()
.setIcon(Icon.DESCRIPTION)
.setTopLabel("Key")
.setContent("Value")
)
)
.addWidget(new WidgetMarkup()
.setTextParagraph(new TextParagraph()
.setText("Incoming webhook")
)
)
.addWidget(new WidgetMarkup()
.addButton(new Button()
.setTextButton(new TextButton()
.setText("Open")
.setOnClick(new OnClick()
.setOpenLink(new OpenLink()
.setUrl("https://gsuite.google.com/products/chat/")
)
)
)
)
)
)
);
superagent.post("https://chat.googleapis.com/v1/spaces/...")
.set("Content-Type", "application/json; charset=UTF-8")
.send(message)
.then((res: superagent.Response) => {
console.log(res.status, res.body);
})
.catch((err: any) => {
console.error(err.response && err.response.text ? JSON.parse(err.response.text) : err);
})
;
Warning
The Api list is coming directly from Google Api, BUT a lot of method are present (ex: keyValue.setBottomLabel
) but don't work with hangouts chat, resulting a response code 200 and a blank message. No way for developper to understand the reason.
Also, the Hangouts Chat message formats documentation is not complete and don't allow to clearly understand how to build message correctly.
You have to test directly on hangout chat in order to be sure that the message will work.
License
MIT © tchiotludo