tambahan
This commit is contained in:
@@ -33,6 +33,7 @@ export default function WaHookHome() {
|
|||||||
<Text>Timestamp: {dayjs(item.data?.entry?.[0]?.changes?.[0]?.value?.messages?.[0]?.timestamp).format("YYYY-MM-DD HH:mm:ss")}</Text>
|
<Text>Timestamp: {dayjs(item.data?.entry?.[0]?.changes?.[0]?.value?.messages?.[0]?.timestamp).format("YYYY-MM-DD HH:mm:ss")}</Text>
|
||||||
<Text>Type: {item.data?.entry?.[0]?.changes?.[0]?.value?.messages?.[0]?.type}</Text>
|
<Text>Type: {item.data?.entry?.[0]?.changes?.[0]?.value?.messages?.[0]?.type}</Text>
|
||||||
<Text>Body: {item.data?.entry?.[0]?.changes?.[0]?.value?.messages?.[0]?.text?.body}</Text>
|
<Text>Body: {item.data?.entry?.[0]?.changes?.[0]?.value?.messages?.[0]?.text?.body}</Text>
|
||||||
|
{JSON.stringify((item.data as any)?.answer)}
|
||||||
</Stack>
|
</Stack>
|
||||||
</Card>
|
</Card>
|
||||||
))}
|
))}
|
||||||
|
|||||||
@@ -60,7 +60,7 @@ const WaHookRoute = new Elysia({
|
|||||||
.post("/hook", async ({ body }) => {
|
.post("/hook", async ({ body }) => {
|
||||||
console.log("Incoming WhatsApp Webhook:", body);
|
console.log("Incoming WhatsApp Webhook:", body);
|
||||||
|
|
||||||
await prisma.waHook.create({
|
const create = await prisma.waHook.create({
|
||||||
data: {
|
data: {
|
||||||
data: body,
|
data: body,
|
||||||
},
|
},
|
||||||
@@ -102,7 +102,22 @@ const WaHookRoute = new Elysia({
|
|||||||
const responseText = await response.text()
|
const responseText = await response.text()
|
||||||
try {
|
try {
|
||||||
const result = JSON.parse(responseText)
|
const result = JSON.parse(responseText)
|
||||||
console.log(result)
|
let createData = create.data as any
|
||||||
|
createData.answer = {
|
||||||
|
text: result.text,
|
||||||
|
type: "text",
|
||||||
|
flow: flow.defaultData,
|
||||||
|
}
|
||||||
|
|
||||||
|
await prisma.waHook.update({
|
||||||
|
where: {
|
||||||
|
id: create.id,
|
||||||
|
},
|
||||||
|
data: {
|
||||||
|
data: createData,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.log(error)
|
console.log(error)
|
||||||
console.log(responseText)
|
console.log(responseText)
|
||||||
|
|||||||
Reference in New Issue
Block a user