Transporte Bilbao Alexa Skill

Este articulo se puede leer en castellano aqui

This alexa skill is accessible at https://www.amazon.es/dp/B09PHW45PS

The objective of this skill is to have next public transports for Bilbao and its surrounding area. Now, it supports lines 1, 2 and 3 of Metro Bilbao .

The interaction with the user is voice based in spanish language:

alexa pidele a transporte bilbao los siguientes metros de matiko a algorta

And if you own a display alexa element such us alexa show , you will get the information also in a graphical card

Python endpoint

Its arquitecture is quite simple, in this case , by the moment it does not support favourite journeys so it is only 2 dockers based, an nginx and a python containers running on the VPS. It is the green block of this diagram, the blue one is common for many other diagrams and its explanation can be seen here

The docker-compose recipe can be seen here, it is interesting the volume used for sharing timezone between host and container, since it is critical for being able to query transport APIs with correct time:

version: '3'
services:
    flaskapp_metro:
        build:
            context: ./
            dockerfile: Dockerfile_flask
        image: flask:0.0.1
        container_name: flaskapp_metro
        volumes:
            - "/home/ubuntu/dockers/metro_alexa/data/scripts:/code/"
            - /etc/localtime:/etc/localtime:ro
        environment:
            - FLASK_APP=/code/metrobot_alexa.py
        command: python /code/metrobot_alexa.py
        networks:
            - alexa_metro
    nginx_metro:
        image: nginx
        depends_on:
          - flaskapp_metro
        container_name: nginx_metro
        networks:
          - proxy_nginx-proxy
          - alexa_metro
        environment:
            - VIRTUAL_HOST=metro.davidestebanmunoz.com
            - LETSENCRYPT_HOST=metro.davidestebanmunoz.com
        volumes:
            - "/home/ubuntu/dockers/metro_alexa/data/nginx/etc_nginx:/etc/nginx"
networks:
    alexa_metro:
    proxy_nginx-proxy:
        external: true 

The dockerfile used for building flask image is this one:

FROM python:3.8-slim
ENV LANG en_US.UTF-8
ENV LANGUAGE en_US:en
ENV LC_ALL en_US.UTF-8

RUN apt-get update && apt-get upgrade -y
RUN apt install -y gcc libssl-dev
RUN pip install https://github.com/botmakerdvd/flask-ask/archive/refs/heads/master.zip
RUN apt remove -y gcc libssl-dev
RUN apt autoremove -y

In this case flask-ask library is used. I forked this library into my repository because I needed to change its behaviour and answer with a 400 Bad Request code when requests are not signed by Alexa . This was mandatory in order to be able to publish this skill into Alexa skills store.

Main Nginx container (the one in blue block) will be responsible of handling the HTTPs keys and certificates so we do not need to worry about this and the nginx configuration file is quite simple:

server {
  listen 80;
  server_name metro.davidestebanmunoz.com;
  location / {
  proxy_pass http://flaskapp_metro:5001;
  proxy_set_header Host "localhost";
  } }

metro.davidestebanmunoz is a A type register in DNS.

Alexa skill

This skill has one intent with 3 slots, “transporte” that for now can be “metro/s” and “tren/es” and “origen” and “destino” that are the stations.

The stations are coded so every information (type of transport operator, line and code for external API) can be extracted from value so no other external DB is needed. Also, using synonims, spanish pronunciation of basque toponims is solved.

Finnally the endpoint of the skill is configured to call https://metro.davidestebanmunoz.com

  • Type: Alexa Skill
  • Where: Docker on VPS
  • Languages and technologies used: Python, flask, Alexa, DNS
  • Github repo: no

One Comment

Leave a Reply

Your email address will not be published. Required fields are marked *