SlideShare a Scribd company logo
Elixir and Lambda talk
with a Telegram bot
Paolo Montrasio
MILAN 25-26 NOVEMBER 2016
Freelancer
paolo.montrasio@connettiva.eu
github.com/pmontrasio
Freelancer
Software architect
paolo.montrasio@connettiva.eu
github.com/pmontrasio
software design, APIs
team management
secure software development
Freelancer
Software architect
Backend developer
Rails Django Web2py Node
paolo.montrasio@connettiva.eu
github.com/pmontrasio
software design, APIs
team management
secure software development
Freelancer
Software architect
Backend developer
Milano Chatbots
Rails Django Web2py Node
meetup.com/Milano-Chatbots-Meetup
paolo.montrasio@connettiva.eu
github.com/pmontrasio
software design, APIs
team management
secure software development
Telegram
@PresenceAlertBot
It tells you how manyWiFi
mac address are in the air
Hello for the menu
/start to start
/stop to end
webhook
receiver
Users
webhook
Users
webhook
receiver
WiFi sensor
Users
Presences
webhook
receiver
WiFi sensor
Users
webhook
receiver
trigger
WiFi sensor
Presences
elixir
WiFi Sensor
elixir
Three layers
1. Functional
2. Object oriented
3. Process supervision
elixir
A look at the code
github.com
pmontrasio/wifi-sensor
elixir
elixir
The entry point
The processes
Dependencies, mix deps.get
Calling Erlang modules
Pattern matching
How to store state in a server
The |> operator
elixir
A more complex project
with object orientation and process supervision
github.com
pmontrasio/decibel
Slides at
connettiva.eu/elixir-phoenix-raspberry-wifi (Italian)
Also check “Elixir's object orientation” at
github.com/pmontrasio/elixir-oo
Receiver
github.com
pmontrasio/wifi-receiver
Elixir and Lambda talk with a Telegram bot - Paolo Montrasio - Codemotion Milan 2016
serverless.yml
serverless deploy
Install Dynamo DB locally
Where to init the client
How to test
Webhook andTrigger
github.com
pmontrasio/wifi-presence-bot
Elixir and Lambda talk with a Telegram bot - Paolo Montrasio - Codemotion Milan 2016
Register the webhook
Receive messages
Configure the trigger
Send messages
News
AWS Lambda environment variables and
serverless architecture
serverless 1.1
$ serverless invoke local -f FUNCTION
Alternatives
Google Cloud Functions, Azure functions
Apex, Gordon
paolo.montrasio@connettiva.eu

More Related Content

PDF
Situational Awareness, Botnet and Malware Detection in the Modern Era - Davi...
PDF
Hacking for Salone: Drone Races - Di Saverio; Lippolis - Codemotion Milan 2016
PPTX
It’s All About Developers. Discover Cisco DevNet. - Jason Goecke - Codemotion...
PDF
The Secret Recipe for Automating Android Malware Analysis - Lorenzo Cavallaro...
PPTX
apidays LIVE New York 2021 - Communication is just as Important as Code by M...
PDF
Making APIs Secure Demands Tracing and Machine Learning to Rapidly Limit Dama...
PDF
hacking_ble_smartwatch @idsecconf2019 cirebon
PPTX
Content without Borders: How Ontologies Help You Provide Customers with Acces...
Situational Awareness, Botnet and Malware Detection in the Modern Era - Davi...
Hacking for Salone: Drone Races - Di Saverio; Lippolis - Codemotion Milan 2016
It’s All About Developers. Discover Cisco DevNet. - Jason Goecke - Codemotion...
The Secret Recipe for Automating Android Malware Analysis - Lorenzo Cavallaro...
apidays LIVE New York 2021 - Communication is just as Important as Code by M...
Making APIs Secure Demands Tracing and Machine Learning to Rapidly Limit Dama...
hacking_ble_smartwatch @idsecconf2019 cirebon
Content without Borders: How Ontologies Help You Provide Customers with Acces...

Viewers also liked (20)

PPTX
DevOps in Cloud, dai Container all'approccio Codeless - Gabriele Provinciali,...
PDF
Milano Chatbots Meetup - Vittorio Banfi - Bot Design - Codemotion Milan 2016
PDF
Distributed System explained (with NodeJS) - Bruno Bossola - Codemotion Milan...
PDF
Keynote: The Most Important Thing - Mike Lee - Codemotion Milan 2016
PDF
Keynote: Community Innovation Alaina Percival - Codemotion Milan 2016
PDF
Games of Simplicity - Pozzi; Molinari - Codemotion Milan 2016
PDF
Big Data, Small Dashboard - Andrea Maietta - Codemotion Milan 2016
PDF
Come rendere il proprio prodotto una bomba creandogli una intera community in...
PDF
Understanding Angular 2 - Shmuela Jacobs - Codemotion Milan 2016
PDF
How To Structure Go Applications - Paul Bellamy - Codemotion Milan 2016
PPTX
Pronti per la legge sulla data protection GDPR? No Panic! - Stefano Sali, Dom...
PDF
Universal JavaScript Web Applications with React - Luciano Mammino - Codemoti...
PDF
Public speaking 4 geeks - Lorenzo Barbieri - Codemotion Milan 2016
ODP
Milano Chatbots Meetup - Paolo Montrasio - Codemotion Milan 2016
PDF
Lo sviluppo di Edge Guardian VR - Marco Giammetti - Codemotion Milan 2016
PPTX
Microservices done right or SOA lessons learnt - Sean Farmar - Codemotion Mil...
PDF
Time to market: when a worse game is better - Mattia Traverso - Codemotion Mi...
PDF
The new features of PHP 7 - Enrico Zimuel - Codemotion Milan 2016
PDF
From a developer to a teamleader — an unexpected journey - Vitaly Sharovatov ...
PPTX
Virtual Reality gaming: analysis of Yon Paradox development - Fabio Mosca - C...
DevOps in Cloud, dai Container all'approccio Codeless - Gabriele Provinciali,...
Milano Chatbots Meetup - Vittorio Banfi - Bot Design - Codemotion Milan 2016
Distributed System explained (with NodeJS) - Bruno Bossola - Codemotion Milan...
Keynote: The Most Important Thing - Mike Lee - Codemotion Milan 2016
Keynote: Community Innovation Alaina Percival - Codemotion Milan 2016
Games of Simplicity - Pozzi; Molinari - Codemotion Milan 2016
Big Data, Small Dashboard - Andrea Maietta - Codemotion Milan 2016
Come rendere il proprio prodotto una bomba creandogli una intera community in...
Understanding Angular 2 - Shmuela Jacobs - Codemotion Milan 2016
How To Structure Go Applications - Paul Bellamy - Codemotion Milan 2016
Pronti per la legge sulla data protection GDPR? No Panic! - Stefano Sali, Dom...
Universal JavaScript Web Applications with React - Luciano Mammino - Codemoti...
Public speaking 4 geeks - Lorenzo Barbieri - Codemotion Milan 2016
Milano Chatbots Meetup - Paolo Montrasio - Codemotion Milan 2016
Lo sviluppo di Edge Guardian VR - Marco Giammetti - Codemotion Milan 2016
Microservices done right or SOA lessons learnt - Sean Farmar - Codemotion Mil...
Time to market: when a worse game is better - Mattia Traverso - Codemotion Mi...
The new features of PHP 7 - Enrico Zimuel - Codemotion Milan 2016
From a developer to a teamleader — an unexpected journey - Vitaly Sharovatov ...
Virtual Reality gaming: analysis of Yon Paradox development - Fabio Mosca - C...
Ad

Similar to Elixir and Lambda talk with a Telegram bot - Paolo Montrasio - Codemotion Milan 2016 (20)

PPTX
Techfest design patterns
PDF
Building Serverless applications with Python
PDF
Origins of Serverless
PDF
Baking a Microservice PI(e)
PDF
INTERFACE by apidays 2023 - How to make APIs AI compatible, Alexandre Airvaul...
PDF
Angular2 & Native Script GDG DevFest 2016
PPTX
Oracle Developer Meetup March 2018
PDF
Micro Frontends
PDF
Comparison of Voice Assistant SDKs for Embedded Linux Devices
PDF
Keeping a codebase fresh for over a decade
PDF
Liferay Italy Symposium 2015 Liferay Mobile SDK and Liferay Screens
PDF
Kubecon SIG Apps December 2017 Update
PDF
A/B Linux updates with RAUC and meta-rauc-community: now & in the future
PPTX
Writing Slack Bots in JavaScript
PPTX
API Design: Women Who Code (WWCode) DFW
PPTX
Orchard CMS: architettura
PDF
Beyond Web Interfaces
PDF
Developer’s guide to contributing code to Kafka with Mickael Maison and Tom B...
PDF
PHP is the King, nodejs the prince and python the fool
PDF
PHP is the king, nodejs is the prince and Python is the fool - Alessandro Cin...
Techfest design patterns
Building Serverless applications with Python
Origins of Serverless
Baking a Microservice PI(e)
INTERFACE by apidays 2023 - How to make APIs AI compatible, Alexandre Airvaul...
Angular2 & Native Script GDG DevFest 2016
Oracle Developer Meetup March 2018
Micro Frontends
Comparison of Voice Assistant SDKs for Embedded Linux Devices
Keeping a codebase fresh for over a decade
Liferay Italy Symposium 2015 Liferay Mobile SDK and Liferay Screens
Kubecon SIG Apps December 2017 Update
A/B Linux updates with RAUC and meta-rauc-community: now & in the future
Writing Slack Bots in JavaScript
API Design: Women Who Code (WWCode) DFW
Orchard CMS: architettura
Beyond Web Interfaces
Developer’s guide to contributing code to Kafka with Mickael Maison and Tom B...
PHP is the King, nodejs the prince and python the fool
PHP is the king, nodejs is the prince and Python is the fool - Alessandro Cin...
Ad

More from Codemotion (20)

PDF
Fuzz-testing: A hacker's approach to making your code more secure | Pascal Ze...
PDF
Pompili - From hero to_zero: The FatalNoise neverending story
PPTX
Pastore - Commodore 65 - La storia
PPTX
Pennisi - Essere Richard Altwasser
PPTX
Michel Schudel - Let's build a blockchain... in 40 minutes! - Codemotion Amst...
PPTX
Richard Süselbeck - Building your own ride share app - Codemotion Amsterdam 2019
PPTX
Eward Driehuis - What we learned from 20.000 attacks - Codemotion Amsterdam 2019
PPTX
Francesco Baldassarri - Deliver Data at Scale - Codemotion Amsterdam 2019 -
PDF
Martin Förtsch, Thomas Endres - Stereoscopic Style Transfer AI - Codemotion A...
PDF
Melanie Rieback, Klaus Kursawe - Blockchain Security: Melting the "Silver Bul...
PDF
Angelo van der Sijpt - How well do you know your network stack? - Codemotion ...
PDF
Lars Wolff - Performance Testing for DevOps in the Cloud - Codemotion Amsterd...
PDF
Sascha Wolter - Conversational AI Demystified - Codemotion Amsterdam 2019
PDF
Michele Tonutti - Scaling is caring - Codemotion Amsterdam 2019
PPTX
Pat Hermens - From 100 to 1,000+ deployments a day - Codemotion Amsterdam 2019
PPTX
James Birnie - Using Many Worlds of Compute Power with Quantum - Codemotion A...
PDF
Don Goodman-Wilson - Chinese food, motor scooters, and open source developmen...
PDF
Pieter Omvlee - The story behind Sketch - Codemotion Amsterdam 2019
PDF
Dave Farley - Taking Back “Software Engineering” - Codemotion Amsterdam 2019
PDF
Joshua Hoffman - Should the CTO be Coding? - Codemotion Amsterdam 2019
Fuzz-testing: A hacker's approach to making your code more secure | Pascal Ze...
Pompili - From hero to_zero: The FatalNoise neverending story
Pastore - Commodore 65 - La storia
Pennisi - Essere Richard Altwasser
Michel Schudel - Let's build a blockchain... in 40 minutes! - Codemotion Amst...
Richard Süselbeck - Building your own ride share app - Codemotion Amsterdam 2019
Eward Driehuis - What we learned from 20.000 attacks - Codemotion Amsterdam 2019
Francesco Baldassarri - Deliver Data at Scale - Codemotion Amsterdam 2019 -
Martin Förtsch, Thomas Endres - Stereoscopic Style Transfer AI - Codemotion A...
Melanie Rieback, Klaus Kursawe - Blockchain Security: Melting the "Silver Bul...
Angelo van der Sijpt - How well do you know your network stack? - Codemotion ...
Lars Wolff - Performance Testing for DevOps in the Cloud - Codemotion Amsterd...
Sascha Wolter - Conversational AI Demystified - Codemotion Amsterdam 2019
Michele Tonutti - Scaling is caring - Codemotion Amsterdam 2019
Pat Hermens - From 100 to 1,000+ deployments a day - Codemotion Amsterdam 2019
James Birnie - Using Many Worlds of Compute Power with Quantum - Codemotion A...
Don Goodman-Wilson - Chinese food, motor scooters, and open source developmen...
Pieter Omvlee - The story behind Sketch - Codemotion Amsterdam 2019
Dave Farley - Taking Back “Software Engineering” - Codemotion Amsterdam 2019
Joshua Hoffman - Should the CTO be Coding? - Codemotion Amsterdam 2019

Recently uploaded (20)

PPTX
Digital-Transformation-Roadmap-for-Companies.pptx
PPTX
MYSQL Presentation for SQL database connectivity
PPTX
sap open course for s4hana steps from ECC to s4
PDF
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
PDF
Encapsulation theory and applications.pdf
PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
PDF
Mobile App Security Testing_ A Comprehensive Guide.pdf
PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
PDF
Review of recent advances in non-invasive hemoglobin estimation
PDF
Agricultural_Statistics_at_a_Glance_2022_0.pdf
PPTX
Big Data Technologies - Introduction.pptx
PDF
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
PDF
Building Integrated photovoltaic BIPV_UPV.pdf
PDF
Network Security Unit 5.pdf for BCA BBA.
PDF
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
PDF
Assigned Numbers - 2025 - Bluetooth® Document
PPTX
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
PDF
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
PDF
Dropbox Q2 2025 Financial Results & Investor Presentation
PDF
gpt5_lecture_notes_comprehensive_20250812015547.pdf
Digital-Transformation-Roadmap-for-Companies.pptx
MYSQL Presentation for SQL database connectivity
sap open course for s4hana steps from ECC to s4
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
Encapsulation theory and applications.pdf
Reach Out and Touch Someone: Haptics and Empathic Computing
Mobile App Security Testing_ A Comprehensive Guide.pdf
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
Review of recent advances in non-invasive hemoglobin estimation
Agricultural_Statistics_at_a_Glance_2022_0.pdf
Big Data Technologies - Introduction.pptx
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
Building Integrated photovoltaic BIPV_UPV.pdf
Network Security Unit 5.pdf for BCA BBA.
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
Assigned Numbers - 2025 - Bluetooth® Document
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
Dropbox Q2 2025 Financial Results & Investor Presentation
gpt5_lecture_notes_comprehensive_20250812015547.pdf

Elixir and Lambda talk with a Telegram bot - Paolo Montrasio - Codemotion Milan 2016

Editor's Notes

  • #2: https://creativecommons.org/licenses/by-nc/3.0/
  • #3: https://creativecommons.org/licenses/by-nc/3.0/
  • #8: When you talked to the bot Telegram’s backend sent a HTTPS request to a webhook with JSON data. The webhook is a JavaScript function on AWS Lambda.
  • #9: It stores your user ID in a Dynamo DB table, Users.
  • #10: The Raspberry sends the count of unique WiFi mac addresses to another JavaScript function on AWS Lambda, once per minute.
  • #11: The count is timestamped and stored in another DynamoDB table, Presences.
  • #12: A trigger on Dynamo DB calls a third AWS Lambda function every time some data is added to Presences. That function gets all the Telegram user ids from Users and sends them a message with the count.
  • #13: The WiFi sensor on the Raspberry is implemented in Elixir.
  • #14: Elixir is a concurrent functional language running on the BEAM virtual machine, derived from Erlang with a Ruby like syntax. Elixir processes exchange data by sending messages to each other, much like OO method calls. A typical Elixir application has many processes because they are cheap to create, run and send messages to. Millions of processes are not unheard of, much like millions of objects in OO languages. But processes are concurrent and use all the cores of the machine. Finally there is a process supervision layer to restart processes if the fail, much like upstart of systemd.
  • #17: The entry point is mix.exs, which by default runs the run function in lib/sensor.ex Task.start_link creates a supervised process ChannelHopper.hop: tail call optimization MacAddressCounter: how to build a server spawn fn - > creates a process. Think: new Class :module.function is a call to an Erlang module
  • #19: Everybody knows AWS Lambda?
  • #20: Show the function at https://github.com/pmontrasio/wifi-receiver/blob/master/handler.js new AWS.DynamoDB.DocumentClient() outside the function, to save time (container reuse) Easy but we must automate the deployment and the creation of the https endpoint.
  • #21: $ serverless create --template aws-nodejs --name receiver serverless.yml defines how to create the environment on AWS Lambda and how to deploy the application. docs/Serverless_Setup.md is step by step guide at how to create and deploy the receiver. docs/DynamoDB.md to install Dynamo DB locally test/README.md on how to test. The important point is to be able to run the assertions in the callback run at the end of the function.
  • #24: The webhook must be registered on Telegram. presenceAlertWebhook gets the message in event.body.message presenceNotifier can be called once with many database Records, in the event.Records array. The trigger must be configured manually in the AWS console. See README.md for the details Messages are sent with a POST to Telegrams. Don’t use npm modules unless you really have to: every ms is important. Billed by 100 ms units.
  • #25: https://aws.amazon.com/blogs/aws/new-for-aws-lambda-environment-variables-and-serverless-application-model/ https://cloud.google.com/functions/ https://azure.microsoft.com/en-us/services/functions/ http://apex.run/ https://github.com/jorgebastida/gordon