Skip to content

Commit

Permalink
expose-send-message
Browse files Browse the repository at this point in the history
  • Loading branch information
uriva committed Sep 5, 2024
1 parent d638847 commit af716d6
Showing 1 changed file with 14 additions and 10 deletions.
24 changes: 14 additions & 10 deletions src/greenApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,19 @@ const communications = <T extends TaskHandler>(
injectReply(send)<T>,
);

export const sendGreenApiMessage =
(secrets: GreenCredentials) => (to: string) =>
pipe(
convertToWhatsAppFormat,
(txt: string) =>
greenApi.restAPI(secrets).message.sendMessage(
to + phoneSuffix,
null,
txt,
),
({ idMessage }: MessageResponse) => idMessage,
);

export const greenApiHandler = (
credentials: GreenCredentials,
path: string,
Expand All @@ -132,15 +145,6 @@ export const greenApiHandler = (
msg.idMessage,
greenApiReferenceId(msg) ?? "",
messageSender(msg),
pipe(
convertToWhatsAppFormat,
(txt: string) =>
greenApi.restAPI(credentials).message.sendMessage(
messageSender(msg) + phoneSuffix,
null,
txt,
),
({ idMessage }: MessageResponse) => idMessage,
),
sendGreenApiMessage(credentials)(messageSender(msg)),
)(doTask)({ text: messageText(msg) }),
});

0 comments on commit af716d6

Please sign in to comment.