All Projects → circuit → Circuit Sdk

circuit / Circuit Sdk

Licence: other
JavaScript and Node.js SDK for Circuit

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to Circuit Sdk

Botlibre
An open platform for artificial intelligence, chat bots, virtual agents, social media automation, and live chat automation.
Stars: ✭ 412 (+2188.89%)
Mutual labels:  bot, sdk
Aws Lex Web Ui
Sample Amazon Lex chat bot web interface
Stars: ✭ 500 (+2677.78%)
Mutual labels:  bot, webrtc
Line Bot Sdk Ruby
LINE Messaging API SDK for Ruby
Stars: ✭ 425 (+2261.11%)
Mutual labels:  bot, sdk
Skylinkjs
SkylinkJS Javascript WebRTC SDK
Stars: ✭ 269 (+1394.44%)
Mutual labels:  sdk, webrtc
Line Bot Sdk Go
LINE Messaging API SDK for Go
Stars: ✭ 654 (+3533.33%)
Mutual labels:  bot, sdk
Oorja
[archived] effortless video-voice chat with realtime collaborative features. extensible using react components 🙌
Stars: ✭ 270 (+1400%)
Mutual labels:  collaboration, webrtc
Line Bot Sdk Java
LINE Messaging API SDK for Java
Stars: ✭ 484 (+2588.89%)
Mutual labels:  bot, sdk
Botpress
🤖 Dev tools to reliably understand text and automate conversations. Built-in NLU. Connect & deploy on any messaging channel (Slack, MS Teams, website, Telegram, etc).
Stars: ✭ 9,486 (+52600%)
Mutual labels:  bot, sdk
Botbuilder Dotnet
Welcome to the Bot Framework SDK for .NET repository, which is the home for the libraries and packages that enable developers to build sophisticated bot applications using .NET.
Stars: ✭ 631 (+3405.56%)
Mutual labels:  bot, sdk
Line Bot Sdk Php
LINE Messaging API SDK for PHP
Stars: ✭ 601 (+3238.89%)
Mutual labels:  bot, sdk
Viber Bot Php
Php bot interface to work with Viber API
Stars: ✭ 202 (+1022.22%)
Mutual labels:  bot, sdk
Bigbluebutton
Complete open source web conferencing system.
Stars: ✭ 7,160 (+39677.78%)
Mutual labels:  collaboration, webrtc
Telegram Bot Sdk
🤖 Telegram Bot API PHP SDK. Lets you build Telegram Bots easily! Supports Laravel out of the box.
Stars: ✭ 2,212 (+12188.89%)
Mutual labels:  bot, sdk
Quickblox Ios Sdk
QuickBlox iOS SDK for messaging and video calling
Stars: ✭ 373 (+1972.22%)
Mutual labels:  sdk, webrtc
Botframework Emulator
A desktop application that allows users to locally test and debug chat bots built with the Bot Framework SDK.
Stars: ✭ 1,532 (+8411.11%)
Mutual labels:  bot, sdk
Botbuilder Js
Welcome to the Bot Framework SDK for JavaScript repository, which is the home for the libraries and packages that enable developers to build sophisticated bot applications using JavaScript.
Stars: ✭ 469 (+2505.56%)
Mutual labels:  bot, sdk
Line Bot Sdk Python
LINE Messaging API SDK for Python
Stars: ✭ 1,198 (+6555.56%)
Mutual labels:  bot, sdk
Mirai Ts
🔧 Mirai(QQ Bot) JavaScript/TypeScript SDK for Node.js/Browser
Stars: ✭ 86 (+377.78%)
Mutual labels:  bot, sdk
Pymessager
Python API to develop chatbot on Facebook Messenger Platform
Stars: ✭ 580 (+3122.22%)
Mutual labels:  bot, sdk
Line Bot Sdk Nodejs
LINE Messaging API SDK for Node.js
Stars: ✭ 683 (+3694.44%)
Mutual labels:  bot, sdk

Circuit JavaScript and Node.js SDK

GitHub release Build Status License

Prerequisites

  • Register for a free developer account and create your own OAuth app to get a client_id. See Getting Started for details.

API Reference

https://circuitsandbox.net/sdk/ with most APIs described in the Client class.

Usage

JavaScript

Add the the line below to the HTML file of your app. This will include the latest version of Circuit SDK and make the Circuit object available.

<script type="text/javascript" src="https://unpkg.com/circuit-sdk"></script>

JS SDK can also be imported via CommonJS or AMD. View the repo UMD for the different types of usage, or circuit-ionic-start for example how import the SDK via require using webpack.

Node.js

npm install --save circuit-sdk

Application Types

The majority of apps fall in one of the three types below. Each type uses a different OAuth 2.0 Grant.

  1. Client-side web applications use the JavaScript SDK with the OAuth 2.0 Implicit Grant.

    // No client_secret needed for Implicit Grant. SDK will obtain access token.
    const client = new Circuit.Client({
      client_id: '<your client_id>',
      domain: 'circuitsandbox.net'
    });
    client.logon()
      .then(user => console.log('Logged on as ' + user.displayName))
    
  2. Server-side web applications use the JavaScript SDK (or REST API) on the client, but handle the authentication flow on the server using the OAuth 2.0 Authorization Code Grant. The access token is obtained on the server and then passed to the client to use in the Circuit JavaScript SDK. These apps may also use the Node.js SDK on the server side to act on behalf of the user.
    Example apps: node-linkify or circuit-google-assistant

    // access token is obtained and managed by server-side app
    const client = new Circuit.Client({
      client_id: '<your client_id>',
      domain: 'circuitsandbox.net'
    });
    client.logon({accessToken: '<access_token>'})
      .then(user => console.log('Logged on as ' + user.displayName))
    
  3. Bots use the Node.js SDK or the REST API and use the OAuth 2.0 Client Credentials Grant. Bots are a special type of user; they don't login on behalf of a regular user, hence no OAuth popup asking for a user`s credentials and permissions.
    Example bots: xlator-bot or node-sdk-example
    Example electron bots: webrtc-bot-example or live-cam-bot

    const Circuit = require('circuit-sdk');
    const client = new Circuit.Client({
      client_id: '<client_id>',
      client_secret: '<client_secret>',
      domain: 'circuitsandbox.net'
    });
    client.logon()
      .then(user => console.log('Logged on as bot: ' + user.emailAddress))
    

Examples

JavaScript examples are located at /examples/js with more examples on jsbin.

Node.js example apps are on github. A summary is listed here. Runkit allows playing with Node.js modules live, similar to jsbin or jsfiddle on the client. Try it on runkit

Here are some snippets to get you started.

Create Group Conversation and send text message

Logon as bot, create a group conversation with two users and send a text message.

client.logon()
  .then(user => console.log(`Logged on as ${user.displayName}`, user))
  .then(() => client.getUsersByEmail(['[email protected]', '[email protected]']))
  .then(users => users.map(user => user.userId))
  .then(userIds => client.createGroupConversation(userIds, 'runkit example'))
  .then(conv => client.addTextItem(conv.convId, 'I am test bot. What can I do for you?'))
  .then(client.logout)
  .catch(console.error)

Get Conversations

Get 10 newest conversations of logged on user.

client.getConversations({numberOfConversations: 10})
  .then(conversations => console.log(`Retrieved ${conversations.length} conversations`))

Video call with another Circuit user

Start a video call with another user. Create conversation if not yet existing.

Only applicable to JavaScript SDK and only on browsers supporting WebRTC

client.makeCall('[email protected]', {audio: true, video: true}, true)
  .then(call => console.log('New call: ', call));

Listen for events

// Register new items added to the feed of this user. E.g. incoming text message
client.addEventListener('itemAdded', item =>
  console.log('itemAdded event received:', item));

// Register for connection state changes
client.addEventListener('connectionStateChanged', evt => {
  console.log(`New state is ${evt.state}`);
});

// Register and log all events
Circuit.supportedEvents.forEach(e => client.addEventListener(e, console.log));

Create an injector

Injectors allow extending the conversation, item and user objects within the SDK. In this example a new attribute teaser is created on the item object. This teaser will be added to item objects in any reponse or event from the SDK.

Circuit.Injectors.itemInjector = function (item) {
  if (item.type === Circuit.Enums.ConversationItemType.TEXT) {
    // Create item.teaser attribute with replacing br and hr tags with a space
    item.teaser = item.text.content.replace(/<(br[\/]?|\/li|hr[\/]?)>/gi, ' ');
  } else {
    item.teaser = item.type;
  }
};

Supported Browsers

Chrome and Firefox are officially supported.

Help us improve the SDK

Help us improve the SDK or examples by sending us a pull-request or opening a GitHub Issue.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].