Hey guys,
I’m getting a Streams response back to my webhook from moralis, however there’s not much info available on processing this data and uploading it to mongodb. How exactly can I go about this?
I’ve found two loose examples, however I’m not sure how to implement them:
Assuming I have to use this function, how do I get the data for it to parse and should I put this function in my index.ts?
export function parseEventData(req: any) {
try {
const updates: any = {};
for (const log of req.body.logs) {
const abi = req.body.abis[log.streamId];
if (abi) {
const { filter, update, eventName } = realtimeUpsertParams(abi, log, req.body.confirmed, req.body.block);
return { data: update, tagName: log.tag, eventName };
}
}
} catch (e: any) {
console.log(e);
}
}
Assuming this block of code is what I have to use to update my mongodb, how can I structure the updateDataInMongo()
below?
app.post('/webhooks/myevent', async (req: any, res: any) => {
try {
verifySignature(req, config.MORALIS_API_KEY);
const { data, tagName, eventName }: any = parseEventData(req);
await updateDataInMongo(tagName, data);
console.log('minted', tagName, eventName)
} catch (e) {
console.log(e);
}
res.send('ok');
});
Thanks!