Skip to content

Commit

Permalink
Merge pull request #12 from takenet/feature/151483-Sending_accout_att…
Browse files Browse the repository at this point in the history
…rs_for_guests

Creating user id on blipchat widget and sending it with account data
  • Loading branch information
luizguicl authored Oct 24, 2019
2 parents d4e1b74 + 5efa60a commit 1b7b131
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 5 deletions.
3 changes: 2 additions & 1 deletion .babelrc
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{
"presets": ["es2015"]
"presets": ["es2015"],
"plugins": ["transform-object-rest-spread"]
}
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

# Installation

Add the script element inside the **body** of your web page. To get the script with your app key, go to [BLiP portal][1]. Choose the desired bot, go to the upper menu and access `Channels > Blip Chat`. On the `Setup` tab you will be able to get the required script. You also have to sign up all website domains into which Blip Chat will be included, otherwise it will not work.
Add the script element inside the **body** of your web page. To get the script with your app key, go to [BLiP portal][1]. Choose the desired bot, go to the upper menu and access `Channels > Blip Chat`. On the `Setup` tab you will be able to get the required script. You also have to sign up all website domains into which Blip Chat will be included, otherwise it will not work.
That's all :)

*For **publishing** purposes, download the script and make a reference to it locally. CDN may have availability problems and cause BLiP Chat instability.*
Expand All @@ -18,7 +18,7 @@ That's all :)
window.onload = function () {
new BlipChat()
.withAppKey('YOUR-APP-KEY')
.withButton({"color":"#2CC3D5"})
.withButton({"color":"#2CC3D6"})
.build();
}
})();
Expand Down
13 changes: 11 additions & 2 deletions src/BlipChatWidget.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import blipIcon from './images/brand-logo.svg'
import Constants from './utils/Constants.js'
import StorageService from './utils/StorageService.js'
import { NotificationHandler } from './utils/NotificationHandler'
import { dom } from './utils/Misc'
import { dom, misc } from './utils/Misc'

// Core
import { BlipChat } from './BlipChat'
Expand Down Expand Up @@ -392,7 +392,16 @@ export class BlipChatWidget {

_getObfuscatedUserAccount() {
if (!self.authConfig || self.authConfig.authType === Constants.GUEST_AUTH) {
return StorageService.getFromLocalStorage(Constants.USER_ACCOUNT_KEY)
const localUserAccount = StorageService.getFromLocalStorage(Constants.USER_ACCOUNT_KEY)

if (!localUserAccount) {
const { botIdentifier } = misc.decodeBlipKey(self.appKey)
let userAccount = misc.createGuestUser(botIdentifier)
userAccount = { ...userAccount, ...self.account }
return window.btoa(JSON.stringify(userAccount))
} else {
return localUserAccount
}
} else if (self.authConfig.authType === Constants.DEV_AUTH) {
let userAccount = self.account
userAccount.userIdentity = self.authConfig.userIdentity
Expand Down
16 changes: 16 additions & 0 deletions src/utils/Misc.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
import * as uuid from 'uuid'

export const misc = {
decodeBlipKey(encodedkey) {
const [identifier, key] = window.atob(encodedkey).split(':')

return { botIdentifier: identifier, botKey: key }
},
createGuestUser(botIdentity) {
return {
userIdentity: `${uuid.v4()}.${botIdentity}`,
userPassword: window.btoa(uuid.v4())
}
}
}

export const dom = {
createDiv(selector) {
const div = document.createElement('div')
Expand Down

0 comments on commit 1b7b131

Please sign in to comment.