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

Fix Bandwidth sending #2490

Merged
merged 1 commit into from
Oct 18, 2024
Merged
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
41 changes: 21 additions & 20 deletions src/extensions/service-vendors/bandwidth/messaging.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Configuration, MessagesApiFp } from "bandwidth-sdk";
import { Configuration, MessagesApi } from "bandwidth-sdk";
import { log } from "../../../lib";
import { getFormattedPhoneNumber } from "../../../lib/phone-format";
import { getConfig } from "../../../server/api/lib/config";
Expand Down Expand Up @@ -38,7 +38,7 @@ export async function getBandwidthController(organization, config) {
username: config.userName,
password: config.password
});
return new MessagesApiFp(client);
return new MessagesApi(client);
}

export async function sendMessage({
Expand Down Expand Up @@ -106,7 +106,6 @@ export async function sendMessage({
bandwidthMessage.media = [parsedMessage.mediaUrl];
}

let response;
if (/bandwidthapitest/.test(message.text)) {
let err;
const response = {
Expand All @@ -131,15 +130,24 @@ export async function sendMessage({
organization,
config
);
response = await messagingController.createMessage(
const { status, data } = await messagingController.createMessage(
config.accountId,
bandwidthMessage
);
console.log(
"bandwidth.sendMessage createMessage response",
response && response.statusCode,
response && response.result
status,
data
);
await postMessageSend({
status,
data,
message,
contact,
trx,
organization,
changes
});
} catch (err) {
console.log("bandwidth.sendMessage ERROR", err);
await postMessageSend({
Expand All @@ -152,22 +160,15 @@ export async function sendMessage({
});
return;
}
await postMessageSend({
response,
message,
contact,
trx,
organization,
changes
});
}

export async function postMessageSend({
message,
contact,
trx,
err,
response,
status,
data,
organization,
changes
}) {
Expand All @@ -181,10 +182,10 @@ export async function postMessageSend({
organization_id: organization.id,
service: "bandwidth"
};
if (response && response.statusCode === 202 && response.result) {
changesToSave.service_id = response.result.id;
if (status && status === 202 && data) {
changesToSave.service_id = data.id;
organizationContact.status_code = 1;
organizationContact.user_number = response.result.from;
organizationContact.user_number = data.from;
cacheableData.campaignContact.updateStatus(
contact,
undefined,
Expand All @@ -193,8 +194,8 @@ export async function postMessageSend({
} else {
// ERROR
changesToSave.send_status = "ERROR";
changesToSave.error_code = response.statusCode;
organizationContact.last_error_code = response.statusCode;
changesToSave.error_code = status;
organizationContact.last_error_code = status;
}
let updateQuery = r.knex("message").where("id", message.id);
if (trx) {
Expand Down