Giter Club home page Giter Club logo

etuovi-notifier's Introduction

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 [email protected]:my-app.git. (Requires heroku.personal host to SSH config as well.)
  6. git push prod

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.