Giter Club home page Giter Club logo

hangouts-chat-api's Introduction

hangouts-chat-api

Node.js wrapper for Google's Hangouts Chat REST API

license npm Travis Dependency Status devDependency Status

What is hangouts-chat-api?

hangouts-chat-api makes sending notifications to Google Hangouts Chat rooms easy.

How do I install it?

First thing first, let's make sure you have the necessary pre-requisites.

System Dependencies

Node

Package

  • npm install hangouts-chat-api

API

HangoutsChatNotification(domain, roomId, authToken)

Creates an instance of HangoutsChatNotification

domain

Type: string

The domain the HangoutsChat server is running on. Ex: https://www.example.com

roomId

Type: string

The room id of the HangoutsChat room the notification should be posted to.

authToken

Type: string

The auth token for the HangoutsChat room the notification should be posted to.

.setFrom(name)

Sets the from name of the message

name

Type: string

A label to be shown in addition to the sender's name

.setTextMessageFormat()

Set message format to 'text' instead of 'html'.

.setColor(color)

Sets color of the message

color

Type: string

Valid values include: yellow, green, red, purple, gray, and random.

.shouldNotify()

Message notifies members of the room.

.setMessage(message)

Sets message of notfication

message

Type: string

The message body

.addCard(id, style, title)

Converts notification to card instead of a basic message.

id

Type: string

An id that will help HangoutsChat recognise the same card when it is sent multiple times.

style

Type: string

Type of the card. Valid values are file, image, application, link, and media.

title

Type: string

The title of the card.

.addCardThumbnail(url)

Adds thumbnail to card.

url

Type: string

The thumbnail url.

.addCardThumbnailDetails(url, url2x, width, height)

Adds thumbnail with retina support to card.

url

Type: string

The thumbnail url.

url2x

Type: string

The thumbnail url in retina.

width

Type: string

The original width of the image.

height

Type: string

The original height of the image.

.addActivity(html)

Adds activity to card.

html

Type: string

Html for the activity to show in one line a summary of the action that happened.

.addActivityWithIcon(html, iconUrl)

Add activity with icon to card.

html

Type: string

Html for the activity to show in one line a summary of the action that happened.

iconUrl

Type: string

The url where the icon is.

.addActivityWithIconDetails(html, iconUrl, icon2xUrl)

Adds activity with icon that has retina support to card.

html

Type: string

Html for the activity to show in one line a summary of the action that happened.

iconUrl

Type: string

The url where the icon is.

icon2xUrl

Type: string

The url for the icon in retina.

.setCardToCompactFormat()

Sets card to compact format.

.setCardToMediumFormat(id, style, title)

Sets card to medium format.

.addCardUrl(url)

Sets card url

url

Type: string

URL that should open when the card is clicked.

.addCardDescription(description, format)

Sets card description.

description

Type: string

The description in the specific format.

format

Type: string

Description format. Valid values include: html and text.

.addCardAttribute(label, description, style)

Adds an attribute to a card.

label

Type: string

Label for the attribute of the card.

description

Type: string

Value of the attribute of the card.

style

Type: string

AUI Integrations for now supporting only lozenges. Valid values: lozenge-success, lozenge-error, lozenge-current, lozenge-complete, lozenge-moved, and lozenge

.addCardAttributeWithUrl(label, description, style, url)

Adds an attribute to a card.

label

Type: string

Label for the attribute of the card.

description

Type: string

Value of the attribute of the card.

style

Type: string

AUI Integrations for now supporting only lozenges. Valid values: lozenge-success, lozenge-error, lozenge-current, lozenge-complete, lozenge-moved, and lozenge

url

Type: string

Url to be opened when a user clicks on the label

.addCardAttributeWithIcon(label, description, style, iconUrl)

Adds an attribute to a card.

label

Type: string

Label for the attribute of the card.

description

Type: string

Value of the attribute of the card.

style

Type: string

AUI Integrations for now supporting only lozenges. Valid values: lozenge-success, lozenge-error, lozenge-current, lozenge-complete, lozenge-moved, and lozenge

iconUrl

Type: string

The url where the icon is

.addCardAttributeWithIconAndUrl(label, description, style, iconUrl, url)

Adds an attribute to a card.

label

Type: string

Label for the attribute of the card.

description

Type: string

Value of the attribute of the card.

style

Type: string

AUI Integrations for now supporting only lozenges. Valid values: lozenge-success, lozenge-error, lozenge-current, lozenge-complete, lozenge-moved, and lozenge

iconUrl

Type: string

The url where the icon is

url

Type: string

Url to be opened when a user clicks on the label

.addCardIcon(iconUrl)

Add icon to card.

iconUrl

Type: string

The url where the icon is.

.addCardIconDetails(iconUrl, icon2xUrl)

Add icon to card.

iconUrl

Type: string

The url where the icon is.

icon2xUrl

Type: string

The url for the icon in retina.

.setRequestDefaults(defaults)

Sets the default options applied to all future requests.

defaults

Type: object

Default request options, see the popular request library for options.

.clearRequestDefaults()

Clears any previously set default options.

.send()

POST a message to the HangoutsChat room API

Returns a Promise. If it succeeds, a string will be returned with a value of successfully posted to hangouts-chat. If it fails, an array of errors is returned.

Examples

Basic Message

const hangoutsChatNotification = new HangoutsChatNotification('https://www.example.com', '1', 'abcd1234');

hangoutsChatNotification.setFrom('From');
hangoutsChatNotification.setColor('green');
hangoutsChatNotification.shouldNotify();
hangoutsChatNotification.setMessage('My message.');

hangoutsChatNotification.send()
  .then((result) => {

  }).catch((error) => {

  });

Simple Card

const notification = new HangoutsChatNotification('https://www.example.com', '1', 'abcd1234');

notification.setFrom('From');
notification.setColor('green');
notification.shouldNotify();
notification.setMessage('My message.');
notification.addCard('1', 'file', 'Title');

notification.send()
  .then((result) => {

  }).catch((error) => {

  });

Complex Card

const notification = new HangoutsChatNotification('https://www.example.com', '1', 'abcd1234');

notification.setFrom('From');
notification.setColor('green');
notification.shouldNotify();
notification.setMessage('My message.');
notification.addCard('1', 'file', 'Title');
notification.addCardAttribute('Size', '128kb', 'lozenge-success');
notification.addCardAttribute('Date', '12/27/2017', 'lozenge-success');

notification.send()
  .then((result) => {

  }).catch((error) => {

  });

Contributing

Please see CONTRIBUTING.md.

Release History

Please see CHANGELOG.md.

License

Copyright (c) 2018 Michael Peterson. Licensed under the MIT license.

hangouts-chat-api's People

Contributors

mwpeterson avatar tclindner avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar

Forkers

nellrcs lennyz71

hangouts-chat-api's Issues

Consider shipping type declarations

Because Typescript is very useful.

As an extremely incomplete example, adding the key "types": "src/HangoutsChatNotification.d.ts" and then setting the following as the contents of src/HangoutsChatNotification.d.ts allows a Typescript consumer to import the class and correctly typecheck its construction:

declare module "hangouts-chat-api" {
    export default class HangoutsChatNotification {
        constructor(webhookUrl: string);
    }
}

Other methods and properties would be declared similarly.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.