Skip to content

CityTrashBot is a Telegram bot created to stay up to date on waste disposal in your area.

License

Notifications You must be signed in to change notification settings

IvanBuccella/CityTrashBot

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

77 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

City Trash Bot

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.

Architecture

The bot has been created using several Azure services, in particular:

The picture below shows the bot architecture and the different services interaction:

Alt text

Tutorial

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.

Prerequisites

Repository

Clone the repository:

$ git clone https://github.com/IvanBuccella/CityTrashBot

Run the bot locally

Environment Variables

  • 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 variables local.settings.json file by using the local.settings.sample.json file.

Install required Modules

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

Run

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

Connect to the local bot

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

Deploy the bot on Azure

Create the Azure Resources

Resource Group

Create a new resource group named city-trash-bot-resource-group as described here.

Web App

Create a new Azure Web App Service resource named city-trash-bot-app as described here to get the botEndpoint.

Bot Service
  • Create a new Azure Bot Service resource named city-trash-bot as described here, to get the MicrosoftAppType, MicrosoftAppId and MicrosoftAppTenantId.
  • Connect the bot resource to Telegram as described here.
Service Bus
  • Create a new Azure Service Bus resource named city-trash-bot-service-bus as described here, to get the SERVICE_BUS_CONNECTION string.
  • Create a new Azure Service Bus Queue resource named named city-trash-bot-queue as described here.
Azure Cosmos DB for MongoDB
  • Create a new Azure Cosmos DB for MongoDB resource named city-trash-bot-db as described here, to get the DATABASE_URL (connection string), DATABASE_NAME.
  • Create a new MongoDB collection named alert, to get the DATABASE_ALERT_COLLECTION.
  • Create a new MongoDB collection named conferiment, to get the DATABASE_CONFERIMENT_COLLECTION.
Function App

Create a new Function App resource named city-trash-bot-functions as described here.

LUIS Service
  • Create a new LUIS resource named city-trash-bot-luis as described here, to get the LuisAPIHostName, LuisAppId, LuisAPIKey.
  • Create a new conversation app named city-trash-bot by importing the app/cognitiveModels/city-trash-bot.json file.
Communication Service
  • Create a new Communication Service resource named city-trash-bot-communication-service as described here, to get the COMMUNICATION_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.
Speech service

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.

Content moderator

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.

Environment Variables

  • Move into the app folder, and set your own template-parameters.json file by editing the template-parameters-sample.json file.
  • Move into the app folder, and set your own environment variables on the Azure Portal for the Web App service by using the .env-sample file.
  • Move into the functions folder, and set your own environment variables on the Azure Portal for the Function App service by using the local.settings.sample.json file.

Deploy the Web App service

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"

Deploy the Function App service

$ cd functions
$ func azure functionapp publish "city-trash-bot-functions"

Deploy the Bot service

$ cd app
$ az deployment group create --resource-group "city-trash-bot-resource-group" --template-file template.json --parameters @template-parameters.json

Contributing

This project welcomes contributions and suggestions. If you use this code, please cite this repository.