Standardize bridge send/receive params
This commit is contained in:
parent
69abe9bee1
commit
c32c26088f
23 changed files with 7042 additions and 1276 deletions
|
|
@ -2,14 +2,14 @@ import { db } from "@link-stack/bridge-common";
|
|||
|
||||
interface SendFacebookMessageTaskOptions {
|
||||
token: string;
|
||||
recipient: string;
|
||||
text: string;
|
||||
to: string;
|
||||
message: string;
|
||||
}
|
||||
|
||||
const sendFacebookMessageTask = async (
|
||||
options: SendFacebookMessageTaskOptions,
|
||||
): Promise<void> => {
|
||||
const { token, text, recipient } = options;
|
||||
const { token, to, message } = options;
|
||||
const { pageId, pageAccessToken } = await db
|
||||
.selectFrom("FacebookBot")
|
||||
.selectAll()
|
||||
|
|
@ -19,17 +19,23 @@ const sendFacebookMessageTask = async (
|
|||
const endpoint = `https://graph.facebook.com/v19.0/${pageId}/messages`;
|
||||
|
||||
const outgoingMessage = {
|
||||
recipient: { id: recipient },
|
||||
message: { text },
|
||||
recipient: { id: to },
|
||||
message: { text: message },
|
||||
messaging_type: "RESPONSE",
|
||||
access_token: pageAccessToken,
|
||||
};
|
||||
|
||||
await fetch(endpoint, {
|
||||
method: "POST",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
body: JSON.stringify(outgoingMessage),
|
||||
});
|
||||
try {
|
||||
const response = await fetch(endpoint, {
|
||||
method: "POST",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
body: JSON.stringify(outgoingMessage),
|
||||
});
|
||||
console.log({ response });
|
||||
} catch (error) {
|
||||
console.error({ error });
|
||||
throw error;
|
||||
}
|
||||
};
|
||||
|
||||
export default sendFacebookMessageTask;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue