Code Monkey home page Code Monkey logo

transit-fedilerts's Introduction

Transit Fedilerts

This project distributes transit alerts via ActivityPub, mainly sourcing from GTFS-realtime Service Alerts feeds. It's primarily built on top of the activitypub-express library.

Currently, Transit Fedilerts is in beta. There may be bugs and features are limited. I welcome issues and pull requests!

The "official" instance lives at transit.alerts.social

Usage

  • Clone the transit-fedilerts repo and install depdencies
  • Define the agencies/services/feeds to include in services.json
    • The structure of this file is documented in the JSON schema format at services.schema.json (example below)
    • While the system looks for services.json by default, you can define a custom path with the environment variable SERVICES_JSON
  • Compile TypeScript and run

HTTPS/SSL

Transit Fedilerts starts up as an HTTP server, but ActivityPub requires HTTPS. A reverse proxy, such as nginx, is recommended to provide SSL support. Setting DOMAIN to localhost will introduce problems; for local development, consider ngrok or other options that provide temporary domain names with SSL.

Environment Variables

Transit Fedilerts uses dotenv for environment variables.

Name Required? Description
DOMAIN X Domain name for the server
MONGO_DB_NAME The name of the MongoDB db to use. Defaults to transitFedilerts
MONGO_URI The connection URI for the Mongo instance. Defaults to mongodb://localhost:27017
NO_FETCH_ALERTS When present, the alert fetchers won't run. Useful for testing other components
PORT Port to run the server on. Defaults to 8080
SERVICES_JSON Custom path to a services configuration file. Defaults to services.json

Example services.json

The config file is intended to be flexible and handle multiple use cases. A service is defined as a single transit entity and translates into an account users can follow, and a feed as the alerts feed itself. This separation will allow for complex use cases, such as agencies whose alerts might be in multiple feeds or feeds which may contain alerts from multiple agencies.

Here's a simple implementation for a single agency with a single feed:

{
    "services": [
        {
            "identifier": "commtrans",
            "name": "Community Transit",
            "iconUrl": "/commtrans.jpg"
        }
    ],
    "feeds": [
        {
            "url": "https://s3.amazonaws.com/commtrans-realtime-prod/alerts.pb",
            "relatesTo": ["commtrans"]
        }
    ]
}

Included in CT's feed are alerts for several Sound Transit routes. Perhaps we want to create a separate Sound Transit feed that includes just those routes:

{
    "services": [
        {
            "identifier": "commtrans",
            "name": "Community Transit",
            "iconUrl": "/commtrans1.jpg"
        },
        {
            "identifier": "soundtransit",
            "name": "Sound Transit (CT)",
            "iconUrl": "/soundtransit-ct1.jpg"
        }
    ],
    "feeds": [
        {
            "url": "https://s3.amazonaws.com/commtrans-realtime-prod/alerts.pb",
            "relatesTo": [
                "commtrans",
                {
                    "identifier": "soundtransit",
                    "criteria": [
                        {
                            "routeId": {
                                "test": "^5\\d\\d$"
                            }
                        }
                    ]
                }
            ]
        }
    ]
}

This will keep all CT-operated service in commtrans and also push anything on an ST route to soundtransit. We could also add feeds for King County Metro and Pierce Transit (the other operators of ST Express buses) and push those to soundtransit based on similar criteria, optionally with additional services for each of them.

Non-GTFS-realtime Alert Feeds

The goal of this project is primarily to support GTFS-realtime Service Alerts, but some non-standard formats are supported. Some implementation details and contribution guidelines:

  • Each individual plugin exists as a subfolder in ./plugins with the plugin ID as the folder name
  • The plugin ID must be defined as literals in services.schema.json and ./models/config.ts
  • The plugin case must be handled in ./alerts/fetchFeed.ts, which returns an array of every found service alert
  • The subfolder should include an index.ts file with the parse method as the default export

Roadmap

The following features are not supported but are on my radar for the future—pull requests that start on these are encouraged. They are in no order.

  • Web interface for prior alerts
    • Currently only show a (very basic) list of services
  • Create actors for individual routes
    • This one's a big lift: Have to ingest and monitor the GTFS-static feed, map route IDs to names, map stops to routes, etc., as well as send a whole lot of messages per alert.
  • Improved Mastodon interopability
    • Implement profile metadata: Official agency URLs? Link to server hosting the instance? More might fit here
    • Implement certain API endpoints, like account statuses and the public timeline
  • Improved reverse proxy support
    • The host must be maintained when passed from the proxy

transit-fedilerts's People

Contributors

kona314 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

transit-fedilerts's Issues

Add Valley Metro (covering the Phoenix metro area)

Agency name: Valley Metro
City/region/other locality: Maricopa County, AZ (Phoenix, Tempe, Chandler, and more.)
Link to alerts feed docs/info (if known):
GTFS-RT URL: https://app.mecatran.com/utw/ws/gtfsfeed/alerts/valleymetro?apiKey=4f22263f69671d7f49726c3011333e527368211f&asJson=true
More documentation: https://www.phoenixopendata.com/dataset/general-transit-feed-specification (linked from Valley Metro's website: https://www.valleymetro.org/contact/developers-resources)

Other comments/discussion: Valley Metro is a really generic name. I wonder if you want to use that or some locality-prefixed name like 'phxvalley` 😆 .

Add NYC MTA

I believe service alerts are published for each line.

TriMet: All messages about blocking trains are dated 2018-11-16

This is a strange one. For the TriMet feed, any post that is related to a blocking train arrive in my Mastodon instance with a published date of 2018-11-16 at 18:50, regardless of when they are sent and arrive. They are commingled amongst other messages that have the current date/time. This has been happening since the TriMet data source was added.

Some examples:
https://transit.alerts.social/o/6446a1e79b136eac97572217
https://transit.alerts.social/o/6446a1e79b136eac97572219
https://transit.alerts.social/o/64453a229b136eac97571da6

Show affected stop

A number of the alerts on the Muni feed are for stop relocations, and the message alone doesn't give enough information to show which stop was relocated:

image

In this case, the Entity Selector attached to the GTFS-Realtime alert probably contains a stop_id, which could be looked up in the static GTFS dump to get the stop name, and add that to the toot.

Add TransLink (Metro Vancouver, BC)

Agency name: TransLink
City/region/other locality: Metro Vancouver, BC, Canada

Link to alerts feed docs/info (if known):

Add Lane Transit District

Agency name: Lane Transit District
City/region/other locality: Lane County, Oregon (primarily the Eugene-Springfield area)
Link to alerts feed docs/info (if known):
https://www.transit.land/feeds/f-ltd~rt (not official but I couldn't find any official docs from LTD)
Other comments/discussion:
Seems to have multiple feeds rather than one?

Add AAATA

I realize that over time it might be hard to run this for every transit agency!

AAATA (aka "The Ride") serves the Ann Arbor area. Their data information is at

https://www.theride.org/business/software-developers

It looks like they have both a GTFS feed and an API. Is it possible to implement your alert system with this, or is more info or more data needed?

Eventually I'd hope for a bot to serve the a2mi.social Mastodon instance.

AAATA/TheRide feed issues

I think these both are minor but worth noting, referencing https://transit.alerts.social/u/theride_aata added at #1 :

  1. The terms of service for use of this data is at https://www.theride.org/business/software-developers and reads

Should you use the Data for any purposes, you agree to provide the following legend, prominently displayed: "Transit scheduling, geographic, and real-time data provided by permission of AAATA/TheRide" unless otherwise agreed by AAATA/TheRide in writing. Other than displaying this legend, you are not authorized to make any use of any proprietary service marks of AAATA/TheRide, including the AAATA/TheRide logo, or any confusingly similar variant thereof.

I would suggest that the legend referenced above go on the header for the page https://transit.alerts.social/u/theride_aata where "Automated service alerts for TheRide AATA" is currently listed.

  1. The feed name "theride_aata" is not current and correct - the old name "AATA" ("Ann Arbor Transportation Authority") was replaced by a new name "AAATA" ("Ann Arbor Area Transportation Authority") in 2013 after a new millage included several neighboring communities including Ypsilanti, MI.

https://www.annarbor.com/news/ann-arbor-agrees-to-ypsilantis-request-for-membership-in-aata/

Add TriMet

Hey, thanks for this project! It may already be on your list somewhere, but it’d be great to get a TriMet account following their GTFS data. TriMet serves the greater Portland Metro area. Documentation is available here: https://developer.trimet.org/GTFS.shtml

TriMet feed includes instructions to operators

The TriMet feed seems to include messages to operators which are not particularly well suited to regular consumers of alerts, and mostly end up just adding to noise and generating so many messages it's hard to follow the feed for its AP account.

I would expect the types of messages posted to this feed to more or less match those types of messages that are passed through TriMet's Twitter feed, e.g., https://twitter.com/trimetalerts

Examples:
https://transit.alerts.social/o/6447f3679b136eac97572961
https://transit.alerts.social/o/64483e679b136eac97572af1
https://transit.alerts.social/o/6448919c9b136eac97572d3d
https://transit.alerts.social/o/6448b8489b136eac97572dc5
https://transit.alerts.social/o/644551929b136eac97571e00

Streamline local development setup

I found this project through mastadon and I've been poking around the last few days. I have a few ideas that might help streamline getting other developers up and running that I've prototyped on my local branch. I'd be happy to submit a PR if you're interested. Specifically I've played with and considered

  • Adding https://github.com/nodkz/mongodb-memory-server as a dev dependency to streamline the mongodb setup and installation
  • Dropping SSL cert requirements when running locally
  • Setting the DOMAIN to localhost:8080 when running locally

Let me know if what you think.

Web interface for prior alerts - error "Cannot GET /u/cta"

Noting this as an issue because it's on the roadmap, and because it currently results in some weird user experience.

I'm using Mastodon at https://a2mi.social and I want to inspect the new CTA feed (plugins yay!). Steps here:

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.