Xeio / WanderLost

Lost Ark Wandering Merchant Tracker
MIT License
106 stars 36 forks source link

Please add Telegram notifications #75

Open shmelkin opened 2 years ago

shmelkin commented 2 years ago

Hi Joshua!

I really like your website and me and my brother we use it every day. But not like it is intended. As we do not sit in our browsers all day, it is hard to follow whether an interesting piece of loot spawned. I programmed a crawler that checks ur website and notifies us via Telegram message everytime something desirable spawned. Unfortunately, everytime you edit your page layout, I have to reconfigure some of my script. I think it would be a benefit if you added the option to register a Telegram account (or simply the user ID) in the configuration of your website to automatically send Telegram notifications via a bot. If needed and wanted, I can also assist you with that.

Best regards!

Xeio commented 2 years ago

So probably will not do Telegram specifically. There is #61 where I may add browser push notifications at some point.

As to crawling the site, you probably don't want to do that via a crawl anyway. It would generally be simpler to get a SignalR client library (should be available in most common languages) and connect directly to the https://lostmerchants.com/MerchantHub endpoint. The call interfaces are available here, though it's mostly just calling the SubscribeToServer method with your server name, then listening to the UpdateMerchantGroup mesasges from the server. If you just want to connect and get merchants at the time of connection, you can call GetKnownActiveMerchantGroups for the server though your client won't get real-time updates like that.

shmelkin commented 2 years ago

Thank you for responding and providing details.

I created a script that calls GetKnownActiveMerchantGroups every minute to reduce load, as I don't really need real-time data.

Everything works as expected.

Is it possible to add expiring information and region into the activeMerchants object? Just so my notifications can include that information. Currently only zone is included, which seems incomplete.

Here an result as reference:

{'id': 0, 'server': 'Kadan', 'merchantName': 'Peter', 'activeMerchants': [{'id': 'f1ddc09e-f928-49ef-c283-08da2cce63c2', 'name': 'Peter', 'zone': 'Balankar Mountains', 'card': {'name': 'Gideon', 'rarity': 2}, 'rapport': {'name': 'Magick Cloth', 'rarity': 3}, 'votes': 40}]}

Xeio commented 2 years ago

Expiration is always :55 after the hour. Things like region are in the data file https://github.com/Xeio/WanderLost/blob/main/WanderLost/WanderLost/Client/wwwroot/data/merchants.json

I don't push most of that to keep the message sizes smaller since the client can compute them.

matiasa18 commented 2 years ago

@shmelkin can you share how you made the request to get that response? I'm interested in doing the same through NodeJS

matiasa18 commented 2 years ago

@matiasa18 in short

import signalR from "@microsoft/signalr";

const connection = new signalR.HubConnectionBuilder()
  .withUrl("https://lostmerchants.com/MerchantHub")
  .build();

await connection.start();
await connection.invoke("SubscribeToServer", "Asta");
await connection.on("UpdateMerchantGroup", async (server) => {
  const merchants = await connection.invoke(
      "GetKnownActiveMerchantGroups",
      server
    )
 console.log(merchants)
});

Thanks for this!

Xeio commented 2 years ago

Just FYI it's a little redundant to call get active merchants when you are listening to active calls, normally you'd only want to call GetKnownActiveMerchantGroups when you initially connect (or re-connect). You will automatically get the new merchants as part of the second parameter to "UpdateMerchantGroup".

const connection = new signalR.HubConnectionBuilder()
  .withUrl("https://lostmerchants.com/MerchantHub")
  .build();
connection.keepAliveIntervalInMilliseconds = 4 * 60 * 1000;
connection.serverTimeoutInMilliseconds = 8 * 60 * 1000;

await connection.start();
await connection.invoke("SubscribeToServer", "Galatur");
await connection.on("UpdateMerchantGroup", async (server, merchants) => {
 console.log(merchants)
});

Also you probably want to set your keep alive interval/timeout as set above or you'll disconnect as I've tuned those back a bit.