Skip to content

Commit

Permalink
initial working
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexanderTsarapkine authored and WillieCubed committed Feb 22, 2024
1 parent a4197f7 commit 025bed4
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 49 deletions.
23 changes: 0 additions & 23 deletions src/app/api/enqueue_calls/route.ts

This file was deleted.

2 changes: 2 additions & 0 deletions src/app/api/voice/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ export async function POST(req: NextRequest) {
resp.say("Please hold");
// Add call to task queue
resp.enqueue({ workflowSid: workflowSid });
// const dial = resp.dial({ callerId: bodyFrom });
// dial.client('[email protected]');

} else if (bodyTo) {
// Outgoing call
Expand Down
30 changes: 4 additions & 26 deletions src/lib/hooks/useCalls.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,11 +128,9 @@ export default function useCalls({
};

const initializeDeviceListeners = () => {
console.log("11111111")
if (!device.current) return;
console.log("2222222")

device.current.on("registered", function () {
console.log("POPOP")
console.log("Twilio.Device Ready to make and receive calls!");
});

Expand All @@ -145,10 +143,7 @@ export default function useCalls({
console.log("Twilio.Device Error: " + error.message);
});

console.log("4444444")

device.current.on("incoming", (incomingCall: Call) => {
console.log("55555")
setIncomingCall(true);
setNumber(incomingCall.parameters.From);

Expand Down Expand Up @@ -252,7 +247,6 @@ export default function useCalls({
*/

const makeCall = async (number: string) => {
console.log("dpqpqpqppqpqpqpp ", device.current)
if (!device.current) return;
const params = {
// get the phone number to call from the DOM
Expand All @@ -267,11 +261,9 @@ export default function useCalls({

// TODO uncomment when taskrouter impelemnted
// Turn agent activity status to reserved to prevent agent from receiving incoming calls
const reservedActivity = agentActivities.current?.find(
(activity) => activity.friendlyName === "Reserved"
);

console.log("ADASA", worker.current?.sid, reservedActivity);
// const reservedActivity = agentActivities.current?.find(
// (activity) => activity.friendlyName === "Reserved"
// );

// await fetch(
// `/api/workers/?workspaceSid=${process.env.NEXT_PUBLIC_WORKSPACE_SID}&workerSid=${worker.current?.sid}`,
Expand Down Expand Up @@ -377,24 +369,11 @@ async function initializeDevice(client: string, workerSid: string) {

const value = await token.json();

console.log("VALUE IS ", value)

const device = new Device(value.token, {
logLevel: 1,
codecPreferences: [Call.Codec.Opus, Call.Codec.PCMU],
});

console.log("REGISTERING DEVICE")
console.log(device)

device.on('registered', () => {
console.log('sdfsddsfsdATT');
});

device.on('incoming', (connection) => {
console.log("BEING CALLED")
})

await device.register();
return device;
}
Expand Down Expand Up @@ -430,7 +409,6 @@ const initializeWorker = async (
const token = await tokenResponse.json();

const worker = new Worker(token);
console.log("WORKER IS", worker)
await timeout(1000); // For some reason, this is some much needed black magic
return worker;
} catch (e) {
Expand Down

0 comments on commit 025bed4

Please sign in to comment.