Skip to content

Commit

Permalink
Merge pull request #2490 from aflcio/bandwidth-fix
Browse files Browse the repository at this point in the history
Fix Bandwidth sending
  • Loading branch information
mau11 authored Oct 18, 2024
2 parents f22ce38 + e7aef62 commit e0822f9
Showing 1 changed file with 21 additions and 20 deletions.
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

0 comments on commit e0822f9

Please sign in to comment.