Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: adiciona opção de visualizar admin do plugin crm no envio ativo #4

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions serverless/functions/create-wa-task.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ exports.handler = TokenValidator(async (context, event, callback) => {
workspaceSid,
workflowSid,
queueSid,
merchant,
} = params;

console.log(`Processing request with parameters ${JSON.stringify(params)}`);
Expand All @@ -50,6 +51,7 @@ exports.handler = TokenValidator(async (context, event, callback) => {
toNumber,
fromNumber,
initialNotificationMessage,
merchant,
{
workspace_sid: workspaceSid,
workflow_sid: workflowSid,
Expand Down Expand Up @@ -79,6 +81,7 @@ exports.handler = TokenValidator(async (context, event, callback) => {
toNumber,
fromNumber,
initialNotificationMessage,
merchant,
{
workspace_sid: workspaceSid,
workflow_sid: workflowSid,
Expand Down Expand Up @@ -120,6 +123,7 @@ const validate = async (event) => {
workspaceSid: string(),
workflowSid: string(),
queueSid: string(),
merchant: string(),
});
try {
const params = await schema.validate(event, {
Expand Down Expand Up @@ -174,6 +178,7 @@ const openTaskInteraction = async (
to,
from,
body,
merchant,
routingProperties
) => {
const toNumber = `whatsapp:${to}`;
Expand Down Expand Up @@ -205,6 +210,7 @@ const openTaskInteraction = async (
twilioNumber: from,
channelType: 'whatsapp',
initialNotificationMessage: body,
merchant,
},
},
},
Expand Down
12 changes: 9 additions & 3 deletions src/components/OutboundWaDialog/OutboundWaDialog.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { v4 as uuidv4 } from 'uuid';
import unidecode from 'unidecode';

import taskService from '../../services/TaskService';
import merchantService from '../../services/MerchantService';
import getTemplatesService from '../../services/GetTemplatesService';
import OutboundSenderIdSelector from '../OutboundSenderIdSelector/OuboundSenderIdSelector';

Expand Down Expand Up @@ -210,14 +211,19 @@ class OutboundWaDialog extends React.Component {
});
}

createTask() {
async createTask() {
Actions.invokeAction('SetActivity', {
activitySid: taskService.availableActivitySid,
});
return taskService.createTask(
const merchant = await merchantService.findMerchantByPhoneNumber(
this.state.toNumber
);

return await taskService.createTask(
this.state.fromNumber,
'+55' + this.state.toNumber,
this.state.message
this.state.message,
merchant
);
}

Expand Down
22 changes: 22 additions & 0 deletions src/services/MerchantService.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { Manager } from '@twilio/flex-ui';
import axios from 'axios';

class MerchantService {
manager = Manager.getInstance();
baseUrl = process.env.REACT_APP_GET_MERCHANT_CONTACT_ENDPOINT;

findMerchantByPhoneNumber = async (phoneNumber) => {
return await axios
.post(this.baseUrl, {
Token: this.manager.store.getState().flex.session.ssoTokenPayload.token,
phoneNumber: `whatsapp:+55${phoneNumber}`,
})
.then((response) => {
return response.data.list;
});
};
}

const merchantService = new MerchantService();

export default merchantService;
8 changes: 7 additions & 1 deletion src/services/TaskService.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,12 @@ class TaskService {
workflowSid = process.env.REACT_APP_WORKFLOW_SID;
queueSid = process.env.REACT_APP_TASK_QUEUE_SID;

createTask = async (fromNumber, toNumber, initialNotificationMessage) => {
createTask = async (
fromNumber,
toNumber,
initialNotificationMessage,
merchant
) => {
let data = {
fromNumber,
toNumber,
Expand All @@ -19,6 +24,7 @@ class TaskService {
workspaceSid: this.workspaceSid,
workflowSid: this.workflowSid,
queueSid: this.queueSid,
merchant: JSON.stringify(merchant),
};

return axios.post(this.baseUrl, data).then((response) => {
Expand Down