[Feature] Website live chat (#187)
Co-authored-by: Nithin David Thomas <webofnithin@gmail.com> Co-authored-by: Sojan Jose <sojan@pepalo.com>
This commit is contained in:
16
app/javascript/widget/helpers/actionCable.js
Normal file
16
app/javascript/widget/helpers/actionCable.js
Normal file
@@ -0,0 +1,16 @@
|
||||
import BaseActionCableConnector from '../../shared/helpers/BaseActionCableConnector';
|
||||
|
||||
class ActionCableConnector extends BaseActionCableConnector {
|
||||
constructor(app, pubsubToken) {
|
||||
super(app, pubsubToken);
|
||||
this.events = {
|
||||
'message.created': this.onMessageCreated,
|
||||
};
|
||||
}
|
||||
|
||||
onMessageCreated = data => {
|
||||
this.app.$store.dispatch('conversation/addMessage', data);
|
||||
};
|
||||
}
|
||||
|
||||
export default ActionCableConnector;
|
||||
15
app/javascript/widget/helpers/axios.js
Executable file
15
app/javascript/widget/helpers/axios.js
Executable file
@@ -0,0 +1,15 @@
|
||||
import axios from 'axios';
|
||||
import { APP_BASE_URL } from 'widget/helpers/constants';
|
||||
|
||||
export const API = axios.create({
|
||||
baseURL: APP_BASE_URL,
|
||||
withCredentials: false,
|
||||
});
|
||||
|
||||
export const setHeader = (key, value) => {
|
||||
API.defaults.headers.common[key] = value;
|
||||
};
|
||||
|
||||
export const removeHeader = key => {
|
||||
delete API.defaults.headers.common[key];
|
||||
};
|
||||
12
app/javascript/widget/helpers/constants.js
Executable file
12
app/javascript/widget/helpers/constants.js
Executable file
@@ -0,0 +1,12 @@
|
||||
export const APP_BASE_URL = '';
|
||||
|
||||
export const MESSAGE_STATUS = {
|
||||
FAILED: 'failed',
|
||||
SUCCESS: 'success',
|
||||
PROGRESS: 'progress',
|
||||
};
|
||||
|
||||
export const MESSAGE_TYPE = {
|
||||
INCOMING: 0,
|
||||
OUTGOING: 1,
|
||||
};
|
||||
10
app/javascript/widget/helpers/utils.js
Executable file
10
app/javascript/widget/helpers/utils.js
Executable file
@@ -0,0 +1,10 @@
|
||||
/* eslint-disable import/prefer-default-export */
|
||||
export const isEmptyObject = obj =>
|
||||
Object.keys(obj).length === 0 && obj.constructor === Object;
|
||||
|
||||
export const arrayToHashById = array =>
|
||||
array.reduce((map, obj) => {
|
||||
const newMap = map;
|
||||
newMap[obj.id] = obj;
|
||||
return newMap;
|
||||
}, {});
|
||||
Reference in New Issue
Block a user