sender timestamp in iso format

This commit is contained in:
Nils
2025-08-30 18:21:57 +02:00
parent 1a2b4eb0d3
commit be29291e4e
2 changed files with 7 additions and 6 deletions

View File

@@ -30,5 +30,5 @@ node meshcore-bot.js /dev/tty.usbmodem12345
### Commands
- `!ping`: The bot will respond with "PONG! 🏓".
- `!date`: The bot will respond with the current date and time in ISO format.
- `.ping`: The bot will respond with "PONG! 🏓".
- `.date`: The bot will respond with the current date and time in ISO format.

View File

@@ -58,18 +58,19 @@ connection.on(Constants.PushCodes.MsgWaiting, async () => {
});
async function onContactMessageReceived(message) {
console.log("Received contact message", message);
console.log("[" + (new Date()).toISOString() + "] Contact message", message);
}
async function onChannelMessageReceived(message) {
console.log(`Received channel message`, message);
message.senderTimestampISO = (new Date(message.senderTimestamp * 1000)).toISOString();
console.log("[" + (new Date()).toISOString() + "] Channel message", message);
// handle commands only in own channels, not in public channel with id 0
if(message.channelIdx > 0){
if(message.text.includes("!ping")){
if(message.text.includes(".ping")){
await connection.sendChannelTextMessage(message.channelIdx, "PONG! 🏓 (" + message.pathLen + ")");
return;
}
if(message.text.includes("!date")){
if(message.text.includes(".date")){
await connection.sendChannelTextMessage(message.channelIdx, (new Date()).toISOString());
return;
}