Skip to content

Sends notifications from new apartments in etuovi emails as Telegram messages

License

Notifications You must be signed in to change notification settings

tomi/etuovi-notifier

Repository files navigation

An Azure Function to check for new Etuovi emails in GMail and send links of apartments to Telegram

Setup

  1. Create .env file and fill in the values
cp .env-sample .env
  • TELEGRAM_BOT_TOKEN: string (not base64 encoded) of Telegram bot token.

  • TELEGRAM_BOT_CHANNEL: string (not base64 encoded) of Telegram channel ID.

    For group chats: invite bot to a channel, make the channel a super group, promote bot as admin (so they can post there), and run:

    curl "https://api.telegram.org/bot$TELEGRAM_BOT_TOKEN/getUpdates"
    

    There you can see the chat id of the group, that is the one needed.

  • CREDENTIALS: base64 encoded object of GMail OAuth2 client secrets. See credentials.json in https://developers.google.com/gmail/api/quickstart/nodejs.

  • ACCESS_TOKEN: base64 encoded object of GMail OAuth2 access and refresh token. See token.json in https://developers.google.com/gmail/api/quickstart/nodejs. Needed scopes are:

[
  "https://www.googleapis.com/auth/gmail.readonly",
  "https://www.googleapis.com/auth/gmail.modify"
]

Note that Google Directions API might cost in high volumes. The cost should be very minimal unless you are doing thousands of queries.

  1. Edit the places (places.ts) you are often traveling from your apartment. Could be your work via car, hobby via bicycle, etc. Waypoints can be added but please note that Google doesn't support them in public transit. The arrival time can be spcified for public transit (for example 9AM Monday).

  2. Install the Azure Functions Core Tools

  3. Install dependencies

npm i
  1. Create an email notification in https://www.etuovi.com

Run locally

npx ts-node ./scripts/checkForApartments.ts

Deploy to Azure

  1. Create an Azure Function app and deploy the app there (log in first to az cli):
npm i
npm run build:production
func azure functionapp publish <appname>
  1. Configure the same env variables in .env to the function app

Deploy to Heroku

  1. Create Heroku app
  2. Add environment variables
  3. Add Heroku Scheduler add-on, and configure node -r ts-node/register --max-old-space-size=2048 ./scripts/checkForApartments.ts as the task with comfortable interval.
  4. Add Papertrail add-on for browsing logs easily from browser
  5. Add new git remote for the Heroku app, for example git remote add prod git@heroku.personal:my-app.git. (Requires heroku.personal host to SSH config as well.)
  6. git push prod

About

Sends notifications from new apartments in etuovi emails as Telegram messages

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published