GithubHelp home page GithubHelp logo

isabella232 / nodejs-businesscommunications Goto Github PK

View Code? Open in Web Editor NEW

This project forked from google-business-communications/nodejs-businesscommunications

0.0 0.0 1.0 58 KB

Client library for Google's Business Communications API

License: Apache License 2.0

nodejs-businesscommunications's Introduction

Business Communications is an API for creating, managing, and launching agents for Google's Verified SMS and Business Messages platforms.

Documentation

The documentation for the Business Commmunications API can be found here.

Quickstart

Before you begin

  1. Register with Business Messages.
  2. Once registered, follow the instructions to enable the APIs for your project.

Installing the client library

npm install businesscommunications

Using the client library

function initClientLibrary(serviceAccountFile) {
  // Get the GoogleAPI library
  const {google} = require('googleapis');
  const businesscommunications = require('businesscommunications');

  // Set the scope that we need for the Business Communications API
  const scopes = [
    'https://www.googleapis.com/auth/businesscommunications',
  ];

  // Set the private key to the service account file
  const privatekey = require(serviceAccountFile);

  // Configure a JWT auth client
  let authClient = new google.auth.JWT(
    privatekey.client_email,
    null,
    privatekey.private_key,
    scopes,
  );

  // Initialize the client library
  let bcApi = new businesscommunications.businesscommunications_v1.Businesscommunications({}, google);

  return new Promise(function(resolve, reject) {
    // Authenticate request
    authClient.authorize(function(err, tokens) {
      if (err) {
        console.log('Error initiatizing library.');
      } else {
        resolve({authClient: authClient, bcApi: bcApi});
      }
    });
  });
}

// Authenticate with the API using a service account key file and
// create a test brand
const apiConnector = initClientLibrary('your-service-account-key-file-location');
apiConnector.then((apiObject) => {
  // Setup the parameters for the API call
  const apiParams = {
    auth: apiObject.authClient,
    resource: {
      displayName: 'Test Brand',
    },
  };

  // Create a new brand with the name "Test Brand"
  apiObject.bcApi.brands.create(apiParams, {}, (err, response) => {
    if (err !== undefined && err !== null) {
      console.log('Error creating brand: ' + err);
    } else {
      // Print newly created brand details
      console.log(response.data);
    }
  });
});

Samples

See code examples to see example usage for most API features. The samples' README.md has instructions for running the samples.

Sample Source Code
Brand CRUD Operations source code
Agent CRUD Operations source code
Location CRUD Operations source code

Versioning

This library follows Semantic Versioning.

This library is considered to be General Availability (GA). This means it is stable; the code surface will not change in backwards-incompatible ways unless absolutely necessary (e.g. because of critical security issues) or with an extensive deprecation period. Issues and requests against GA libraries are addressed with the highest priority.

Contributing

Contributions welcome! See the Contributing Guide.

License

Apache Version 2.0

See LICENSE

nodejs-businesscommunications's People

Contributors

adamjchan avatar thefalc avatar

Forkers

jingo369

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.