Recyclable, general waste, food, paper, glass... "What should I take out today?", "When Is the glass trash collected?" Feel free to ask CityTrashBot!
CityTrashBot is a Telegram bot created to stay up to date on waste disposal in your area.
Just interact with it via text or audio message, and immediately receive a detailed answer to all your questions! Just make sure to be mindful with your words…it might take offence!
With CityTrashBot it's possible to receive daily waste disposal email notifications at set times based on your preference so it can keep you up to date on what’s going on with waste disposal in your area!
CityTrashBot has the following features:
- find out the type of waste to take out for collection in a specific city and day of the week;
- find out the day of waste collection of a specific type of waste in a specific city;
- schedule email alerts to receive every day at a specified time about waste collection for a specified city;
- train the bot to keep you updated based on your preferences.
The bot has been created using several Azure services, in particular:
- LUIS, an AI based cognitive service, to implement language understanding;
- Bot Service, to build the bot;
- Web App Service, to implement the bot business logic;
- Functions, to read/write the stored data and manage the notifications system;
- Content Moderator, to moderate the audio and text messages received from the bot;
- Speech Service, to allow the bot to receive and send audio messages;
- Cosmos DB, to store the bot data into collections;
- Service Bus, to allow communication between the different functions;
- Communication Services & Email Communication Service, to deliver the emails to the bot users.
The picture below shows the bot architecture and the different services interaction:
This tutorial shows how to take advantage of the Microsoft Bot Framework and other Azure services to develop a bot to automate some functionalities of interest.
This tutorial also shows how to locally run the bot, and how to deploy it in Azure.
- If you don't have an Azure subscription, create a free account before you begin;
- Visual Studio Code or your favorite IDE, if you want to edit the bot code;
- Knowledge of Node.js, restify and asynchronous programming in JavaScript;
- NVM Node Version Manager
- Azure CLI;
- The Bot Framework SDK for JavaScript;
- Bot Framework Emulator;
- Azure Functions Core Tools;
- Azurite emulator;
- Azure Speech SDK for JavaScript.
Clone the repository:
$ git clone https://github.com/IvanBuccella/CityTrashBot
- Move into the
app
folder, and create your own environment variables.env
file by using the.env-sample
file. - Move into the
functions
folder, and create your own settings variableslocal.settings.json
file by using thelocal.settings.sample.json
file.
Move into the app
folder, and install all the required packages:
$ cd app
$ nvm use
$ npm install
Move into the functions
folder, and install all the required packages:
$ cd functions
$ nvm use
$ npm install
Since the Azurite emulator is required for running locally the Azure functions, you need to start it:
$ cd functions
$ azurite --silent --location azurite
Now, run the functions:
$ cd functions
$ nvm use
$ func start
And then, run the app:
$ cd app
$ nvm use
$ npm start
You can connect to the bot using Bot Framework Emulator:
- Launch Bot Framework Emulator
- File -> Open Bot
- Enter the Bot URL
http://{your hostname}:3978/api/messages
Create a new resource group named city-trash-bot-resource-group
as described here.
Create a new Azure Web App Service resource named city-trash-bot-app
as described here to get the botEndpoint
.
- Create a new Azure Bot Service resource named
city-trash-bot
as described here, to get theMicrosoftAppType
,MicrosoftAppId
andMicrosoftAppTenantId
. - Connect the bot resource to Telegram as described here.
- Create a new Azure Service Bus resource named
city-trash-bot-service-bus
as described here, to get theSERVICE_BUS_CONNECTION
string. - Create a new Azure Service Bus Queue resource named
named city-trash-bot-queue
as described here.
- Create a new Azure Cosmos DB for MongoDB resource named
city-trash-bot-db
as described here, to get theDATABASE_URL
(connection string),DATABASE_NAME
. - Create a new MongoDB collection named
alert
, to get theDATABASE_ALERT_COLLECTION
. - Create a new MongoDB collection named
conferiment
, to get theDATABASE_CONFERIMENT_COLLECTION
.
Create a new Function App resource named city-trash-bot-functions
as described here.
- Create a new LUIS resource named
city-trash-bot-luis
as described here, to get theLuisAPIHostName
,LuisAppId
,LuisAPIKey
. - Create a new conversation app named
city-trash-bot
by importing theapp/cognitiveModels/city-trash-bot.json
file.
- Create a new Communication Service resource named
city-trash-bot-communication-service
as described here, to get theCOMMUNICATION_SERVICES_CONNECTION
string. - Create a new Email Communication Service resource nnamed
city-trash-bot-email-communication-service
as described here; - Create a new Email Communication Services Domain resource as described here, to get the
SENDER_EMAIL_ADDRESS
.
Create a new Speech Service resource named city-trash-bot-speech-services
in the Azure portal to get the resource SPEECH_KEY
and SPEECH_REGION
.
Create a new Content moderator resource named city-trash-bot-content-moderator
in the Azure portal to get CONTENT_MODERATOR_ENDPOINT
(connection string) and CONTENT_MODERATOR_SUBSCRIPTION_KEY
.
- Move into the
app
folder, and set your owntemplate-parameters.json
file by editing thetemplate-parameters-sample.json
file. - Move into the
app
folder, and set your own environment variables on the Azure Portal for theWeb App
service by using the.env-sample
file. - Move into the
functions
folder, and set your own environment variables on the Azure Portal for theFunction App
service by using thelocal.settings.sample.json
file.
Zip your app code and then deploy to Azure:
$ cd app
$ zip -r build.zip . -x ".env" -x "template-parameters.json" -x "template.json" -x "package-lock.json" -x "*.nvmrc" -x "cognitiveModels"
$ az webapp deployment source config-zip --resource-group "city-trash-bot-resource-group" --name "city-trash-bot-app" --src "build.zip"
$ cd functions
$ func azure functionapp publish "city-trash-bot-functions"
$ cd app
$ az deployment group create --resource-group "city-trash-bot-resource-group" --template-file template.json --parameters @template-parameters.json
This project welcomes contributions and suggestions. If you use this code, please cite this repository.