Skip to content

Instantly share code, notes, and snippets.

@enricop89
enricop89 / index.js
Created June 22, 2018 12:46
Widget auth
const fetch = require('node-fetch');
fetch('https://sandbox.bandyer.com/rest/widget/chat/auth/usr_xxxxxx',
{ method: 'GET', headers: { 'Content-Type': 'application/json', apikey: 'ak_test_xxxxxxxxxxxx'},})
.then(res => res.json()) // this is mandatory
.then(json => console.log(json));
BandyerChat.create({
userAlias: result.id,
appId: Drupal.settings.appIdBandyer,
environment: 'sandbox'
}).then(() => {
BandyerChat.addChat(Drupal.settings.opIdBandyer);
BandyerChat.openWidget();
})
@enricop89
enricop89 / logoutAfterTimeout.js
Created October 8, 2018 11:03
Bandyer chat logout after timeout
/**
* This function calls the BandyerChat.logout() method after a specified timeout (default: 5 minutes)
* If BandyerChat widget has not been initialized, the function will throw an error.
* @param timeout
* @param callback
*/
var exitWidgetAfterTimeout = function (timeout, callback) {
if (BandyerChat) {
var delay = timeout || (5* 60 * 1000);
setTimeout(function() {
@enricop89
enricop89 / index.js
Created October 31, 2018 16:25
Bandyer widget create with Screen Sharing Extension
const Client = BandyerChat.create({
userAlias: 'usr_123456',
appId: 'wAppId_fake123456',
environment: 'sandbox',
screenSharingExtensionId: 'id of your screen sharing extension'
});
BandyerChat.setExtensionUrl('https://chrome.google.com/webstore/detail/your-extension/your-extension-id')
@enricop89
enricop89 / index.js
Created December 21, 2018 09:07
User connected Event
const Client = BandyerChat.create({
userAlias: 'usr_123456',
appId: 'wAppId_fake123456',
environment: 'sandbox',
hidden: false,
screenSharingExtensionId: 'id of your screen sharing extension'
});
Client.on('user_connected',(user) => {
if (user.role === 'group_b'){ // your custom logic
@enricop89
enricop89 / index.js
Last active February 8, 2019 16:45
Example of SelectChat
BandyerChat.create({
userAlias: 'usr_123456',
appId: 'wAppId_fake123456',
environment: 'sandbox',
hidden: false,
screenSharingExtensionId: 'id of your screen sharing extension'
});
BandyerChat.addChat('usr_test_1').then(() => {
BandyerChat.selectChat('usr_test_1');
@enricop89
enricop89 / index.js
Created February 19, 2019 08:35
Create Widget - Mode Window
const Client = BandyerChat.create({
userAlias: 'usr_123456',
appId: 'wAppId_fake123456',
environment: 'sandbox',
screenSharingExtensionId: 'id of your screen sharing extension',
mode: 'window'
});
@enricop89
enricop89 / LayoutExample.js
Created February 22, 2019 11:00
Example for custom layout
BandyerChat.create({
userAlias: 'usr_123456',
appId: 'wAppId_fake123456',
environment: 'sandbox',
layout: {
body: {background: '#fff', color: '#000'},
dial:{background: '#fff', color: '#000'},
call: {background: '#C1C6C8', color: '#000'},
messageSent: {background: '#002453', color: '#fff'},
messageReceived: {background: '#C1C6C8', color: '#000'},
@enricop89
enricop89 / GetChat.js
Created February 28, 2019 08:44
Example getChat
BandyerChat.create({
userAlias: 'usr_123456',
appId: 'wAppId_fake123456',
environment: 'sandbox',
hidden: false,
screenSharingExtensionId: 'id of your screen sharing extension'
}).then(()=> {
// Widget loaded
})
@enricop89
enricop89 / BandyerSignature.js
Created April 3, 2019 14:39
How to compute bandyer signature in Webhook Methods
const crypto = require('crypto');
const data = {
event: "on_message_sent",
"event_version": "0.1",
"namespace": "chat",
"data": "{}"
}
const secret = 'ak_fake_123456789';
const timestamp = '1554297654628';