Skip to content

Commit

Permalink
Revert "trigger test"
Browse files Browse the repository at this point in the history
This reverts commit 37ba821.
  • Loading branch information
Luisotee committed Jan 5, 2025
1 parent 37ba821 commit d3125ee
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 62 deletions.
36 changes: 27 additions & 9 deletions apps/whatsapp/src/message/message.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ import { logger } from "@trigger.dev/sdk/v3";
import { type WAMessage, downloadMediaMessage } from "@whiskeysockets/baileys";
import { sock } from "../client";
import { BOT_PREFIX } from "../constants";
import { client } from "../trigger/client";
import type { MessagePayload, MessageResponse } from "../types";
import { getPhoneNumber, react } from "../utils";

const IMAGE_ERROR_MSG =
Expand All @@ -19,6 +17,12 @@ const ERROR_MESSAGES = {
UNKNOWN: "Ocorreu um erro inesperado. Pode tentar novamente?",
};

interface MessagePayload {
message: string;
sessionId: string;
audio?: string; // Changed from Blob to string
}

export async function handleMessage(message: WAMessage) {
await react(message, "working");

Expand Down Expand Up @@ -78,21 +82,35 @@ export async function handleMessage(message: WAMessage) {
}
}

// Use trigger.dev to send message
const eventResponse = await client.sendEvent({
name: "message.send",
payload,
// Make API request to messaging service
const controller = new AbortController();
const timeoutId = setTimeout(() => controller.abort(), 600000);

const response = await fetch("http://localhost:3001/api/messages/send", {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify(payload),
signal: controller.signal,
});

const result = eventResponse.payload as MessageResponse;
clearTimeout(timeoutId);

if (!response.ok) {
console.dir(response, { depth: null });
throw new Error(`HTTP error! status: ${response.status}`);
}

const data = await response.json();

if (!result?.result) {
if (!data.result) {
throw new Error("No result from API");
}

await sock.sendMessage(
chatId,
{ text: result.result, edit: streamingReply.key },
{ text: data.result, edit: streamingReply.key },
{ quoted: message },
);

Expand Down
11 changes: 0 additions & 11 deletions apps/whatsapp/src/schemas.ts

This file was deleted.

7 changes: 0 additions & 7 deletions apps/whatsapp/src/trigger/client.ts

This file was deleted.

30 changes: 0 additions & 30 deletions apps/whatsapp/src/trigger/jobs.ts

This file was deleted.

5 changes: 0 additions & 5 deletions apps/whatsapp/src/types.ts

This file was deleted.

0 comments on commit d3125ee

Please sign in to comment.