Refactor Conversation, Message API calls, store
This commit is contained in:
24
app/javascript/dashboard/api/channel/fbChannel.js
Normal file
24
app/javascript/dashboard/api/channel/fbChannel.js
Normal file
@@ -0,0 +1,24 @@
|
||||
/* global axios */
|
||||
import ApiClient from '../ApiClient';
|
||||
|
||||
class FBChannel extends ApiClient {
|
||||
constructor() {
|
||||
super('facebook_indicators');
|
||||
}
|
||||
|
||||
markSeen({ inboxId, contactId }) {
|
||||
return axios.post(`${this.url}/mark_seen`, {
|
||||
inbox_id: inboxId,
|
||||
contact_id: contactId,
|
||||
});
|
||||
}
|
||||
|
||||
toggleTyping({ status, inboxId, contactId }) {
|
||||
return axios.post(`${this.url}/typing_${status}`, {
|
||||
inbox_id: inboxId,
|
||||
contact_id: contactId,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
export default new FBChannel();
|
||||
@@ -13,6 +13,7 @@ const endPoints = {
|
||||
logout: {
|
||||
url: 'auth/sign_out',
|
||||
},
|
||||
|
||||
me: {
|
||||
url: 'api/v1/conversations.json',
|
||||
params: { type: 0, page: 1 },
|
||||
@@ -23,28 +24,6 @@ const endPoints = {
|
||||
params: { inbox_id: null },
|
||||
},
|
||||
|
||||
conversations(id) {
|
||||
return { url: `api/v1/conversations/${id}.json`, params: { before: null } };
|
||||
},
|
||||
|
||||
resolveConversation(id) {
|
||||
return { url: `api/v1/conversations/${id}/toggle_status.json` };
|
||||
},
|
||||
|
||||
sendMessage(conversationId, message) {
|
||||
return {
|
||||
url: `api/v1/conversations/${conversationId}/messages.json`,
|
||||
params: { message },
|
||||
};
|
||||
},
|
||||
|
||||
addPrivateNote(conversationId, message) {
|
||||
return {
|
||||
url: `api/v1/conversations/${conversationId}/messages.json?`,
|
||||
params: { message, private: 'true' },
|
||||
};
|
||||
},
|
||||
|
||||
fetchLabels: {
|
||||
url: 'api/v1/labels.json',
|
||||
},
|
||||
@@ -86,60 +65,6 @@ const endPoints = {
|
||||
params: { omniauth_token: '' },
|
||||
},
|
||||
|
||||
assignAgent(conversationId, AgentId) {
|
||||
return {
|
||||
url: `/api/v1/conversations/${conversationId}/assignments?assignee_id=${AgentId}`,
|
||||
};
|
||||
},
|
||||
|
||||
fbMarkSeen: {
|
||||
url: 'api/v1/facebook_indicators/mark_seen',
|
||||
},
|
||||
|
||||
fbTyping(status) {
|
||||
return {
|
||||
url: `api/v1/facebook_indicators/typing_${status}`,
|
||||
};
|
||||
},
|
||||
|
||||
markMessageRead(id) {
|
||||
return {
|
||||
url: `api/v1/conversations/${id}/update_last_seen`,
|
||||
params: {
|
||||
agent_last_seen_at: null,
|
||||
},
|
||||
};
|
||||
},
|
||||
|
||||
// Canned Response [GET, POST, PUT, DELETE]
|
||||
cannedResponse: {
|
||||
get() {
|
||||
return {
|
||||
url: 'api/v1/canned_responses',
|
||||
};
|
||||
},
|
||||
getOne({ id }) {
|
||||
return {
|
||||
url: `api/v1/canned_responses/${id}`,
|
||||
};
|
||||
},
|
||||
post() {
|
||||
return {
|
||||
url: 'api/v1/canned_responses',
|
||||
};
|
||||
},
|
||||
put(id) {
|
||||
return {
|
||||
url: `api/v1/canned_responses/${id}`,
|
||||
};
|
||||
},
|
||||
delete(id) {
|
||||
return {
|
||||
url: `api/v1/canned_responses/${id}`,
|
||||
};
|
||||
},
|
||||
},
|
||||
|
||||
reports: {
|
||||
account(metric, from, to) {
|
||||
return {
|
||||
|
||||
@@ -1,104 +1,37 @@
|
||||
/* eslint no-console: 0 */
|
||||
/* global axios */
|
||||
/* eslint no-undef: "error" */
|
||||
/* eslint no-unused-expressions: ["error", { "allowShortCircuit": true }] */
|
||||
import endPoints from '../endPoints';
|
||||
import ApiClient from '../ApiClient';
|
||||
|
||||
export default {
|
||||
fetchConversation(id) {
|
||||
const urlData = endPoints('conversations')(id);
|
||||
const fetchPromise = new Promise((resolve, reject) => {
|
||||
axios
|
||||
.get(urlData.url)
|
||||
.then(response => {
|
||||
resolve(response);
|
||||
})
|
||||
.catch(error => {
|
||||
reject(Error(error));
|
||||
});
|
||||
});
|
||||
return fetchPromise;
|
||||
},
|
||||
class ConversationApi extends ApiClient {
|
||||
constructor() {
|
||||
super('conversations');
|
||||
}
|
||||
|
||||
toggleStatus(id) {
|
||||
const urlData = endPoints('resolveConversation')(id);
|
||||
const fetchPromise = new Promise((resolve, reject) => {
|
||||
axios
|
||||
.post(urlData.url)
|
||||
.then(response => {
|
||||
resolve(response);
|
||||
})
|
||||
.catch(error => {
|
||||
reject(Error(error));
|
||||
});
|
||||
get({ inboxId, convStatus, assigneeStatus }) {
|
||||
return axios.get(this.url, {
|
||||
params: {
|
||||
inbox_id: inboxId,
|
||||
conversation_status_id: convStatus,
|
||||
assignee_type_id: assigneeStatus,
|
||||
},
|
||||
});
|
||||
return fetchPromise;
|
||||
},
|
||||
}
|
||||
|
||||
assignAgent([id, agentId]) {
|
||||
const urlData = endPoints('assignAgent')(id, agentId);
|
||||
const fetchPromise = new Promise((resolve, reject) => {
|
||||
axios
|
||||
.post(urlData.url)
|
||||
.then(response => {
|
||||
resolve(response);
|
||||
})
|
||||
.catch(error => {
|
||||
reject(Error(error));
|
||||
});
|
||||
});
|
||||
return fetchPromise;
|
||||
},
|
||||
toggleStatus(conversationId) {
|
||||
return axios.post(`${this.url}/${conversationId}/toggle_status`, {});
|
||||
}
|
||||
|
||||
markSeen({ inboxId, senderId }) {
|
||||
const urlData = endPoints('fbMarkSeen');
|
||||
const fetchPromise = new Promise((resolve, reject) => {
|
||||
axios
|
||||
.post(urlData.url, {
|
||||
inbox_id: inboxId,
|
||||
sender_id: senderId,
|
||||
})
|
||||
.then(response => {
|
||||
resolve(response);
|
||||
})
|
||||
.catch(error => {
|
||||
reject(Error(error));
|
||||
});
|
||||
});
|
||||
return fetchPromise;
|
||||
},
|
||||
|
||||
fbTyping({ flag, inboxId, senderId }) {
|
||||
const urlData = endPoints('fbTyping')(flag);
|
||||
const fetchPromise = new Promise((resolve, reject) => {
|
||||
axios
|
||||
.post(urlData.url, {
|
||||
inbox_id: inboxId,
|
||||
sender_id: senderId,
|
||||
})
|
||||
.then(response => {
|
||||
resolve(response);
|
||||
})
|
||||
.catch(error => {
|
||||
reject(Error(error));
|
||||
});
|
||||
});
|
||||
return fetchPromise;
|
||||
},
|
||||
assignAgent({ conversationId, agentId }) {
|
||||
axios.post(
|
||||
`${this.url}/${conversationId}/assignments?assignee_id=${agentId}`,
|
||||
{}
|
||||
);
|
||||
}
|
||||
|
||||
markMessageRead({ id, lastSeen }) {
|
||||
const urlData = endPoints('markMessageRead')(id);
|
||||
urlData.params.agent_last_seen_at = lastSeen;
|
||||
const fetchPromise = new Promise((resolve, reject) => {
|
||||
axios
|
||||
.post(urlData.url, urlData.params)
|
||||
.then(response => {
|
||||
resolve(response);
|
||||
})
|
||||
.catch(error => {
|
||||
reject(Error(error));
|
||||
});
|
||||
return axios.post(`${this.url}/${id}/update_last_seen`, {
|
||||
agent_last_seen_at: lastSeen,
|
||||
});
|
||||
return fetchPromise;
|
||||
},
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
export default new ConversationApi();
|
||||
|
||||
@@ -1,32 +0,0 @@
|
||||
/* eslint no-console: 0 */
|
||||
/* global axios */
|
||||
/* eslint no-undef: "error" */
|
||||
/* eslint no-unused-expressions: ["error", { "allowShortCircuit": true }] */
|
||||
import endPoints from '../endPoints';
|
||||
|
||||
export default {
|
||||
fetchAllConversations(params, callback) {
|
||||
const urlData = endPoints('getInbox');
|
||||
|
||||
if (params.inbox !== 0) {
|
||||
urlData.params.inbox_id = params.inbox;
|
||||
} else {
|
||||
urlData.params.inbox_id = null;
|
||||
}
|
||||
urlData.params = {
|
||||
...urlData.params,
|
||||
conversation_status_id: params.convStatus,
|
||||
assignee_type_id: params.assigneeStatus,
|
||||
};
|
||||
axios
|
||||
.get(urlData.url, {
|
||||
params: urlData.params,
|
||||
})
|
||||
.then(response => {
|
||||
callback(response);
|
||||
})
|
||||
.catch(error => {
|
||||
console.log(error);
|
||||
});
|
||||
},
|
||||
};
|
||||
@@ -1,55 +1,24 @@
|
||||
/* eslint no-console: 0 */
|
||||
/* global axios */
|
||||
/* eslint no-undef: "error" */
|
||||
/* eslint no-unused-expressions: ["error", { "allowShortCircuit": true }] */
|
||||
import endPoints from '../endPoints';
|
||||
import ApiClient from '../ApiClient';
|
||||
|
||||
export default {
|
||||
sendMessage([conversationId, message]) {
|
||||
const urlData = endPoints('sendMessage')(conversationId, message);
|
||||
const fetchPromise = new Promise((resolve, reject) => {
|
||||
axios
|
||||
.post(urlData.url, urlData.params)
|
||||
.then(response => {
|
||||
resolve(response);
|
||||
})
|
||||
.catch(error => {
|
||||
reject(Error(error));
|
||||
});
|
||||
});
|
||||
return fetchPromise;
|
||||
},
|
||||
class MessageApi extends ApiClient {
|
||||
constructor() {
|
||||
super('conversations');
|
||||
}
|
||||
|
||||
addPrivateNote([conversationId, message]) {
|
||||
const urlData = endPoints('addPrivateNote')(conversationId, message);
|
||||
const fetchPromise = new Promise((resolve, reject) => {
|
||||
axios
|
||||
.post(urlData.url, urlData.params)
|
||||
.then(response => {
|
||||
resolve(response);
|
||||
})
|
||||
.catch(error => {
|
||||
reject(Error(error));
|
||||
});
|
||||
create({ conversationId, message, private: isPrivate }) {
|
||||
return axios.post(`${this.url}/${conversationId}/messages`, {
|
||||
message,
|
||||
private: isPrivate,
|
||||
});
|
||||
return fetchPromise;
|
||||
},
|
||||
}
|
||||
|
||||
fetchPreviousMessages({ id, before }) {
|
||||
const urlData = endPoints('conversations')(id);
|
||||
urlData.params.before = before;
|
||||
const fetchPromise = new Promise((resolve, reject) => {
|
||||
axios
|
||||
.get(urlData.url, {
|
||||
params: urlData.params,
|
||||
})
|
||||
.then(response => {
|
||||
resolve(response);
|
||||
})
|
||||
.catch(error => {
|
||||
reject(Error(error));
|
||||
});
|
||||
getPreviousMessages({ conversationId, before }) {
|
||||
return axios.get(`${this.url}/${conversationId}`, {
|
||||
params: { before },
|
||||
});
|
||||
return fetchPromise;
|
||||
},
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
export default new MessageApi();
|
||||
|
||||
Reference in New Issue
Block a user