This solution was created to enable receiving messages from sensors placed around the house. The sensors publish messages to a queue via an API, and then a microservice sends them to a Discord channel.
- Rest API
- Worker
Project is created with:
- Fast Endpoints
- Masstransit (RabbitMQ)
- EF Core (PostgresSQL)
Click me
{
"x-generator": "NSwag v14.1.0.0 (NJsonSchema v11.0.2.0 (Newtonsoft.Json v13.0.0.0))",
"openapi": "3.0.0",
"info": {
"title": "MyNotifications.Api",
"version": "1.0.0"
},
"servers": [
{
"url": "http://localhost:8080"
}
],
"paths": {
"/notifications": {
"post": {
"tags": [
"Notifications"
],
"operationId": "MyNotificationsApiEndpointsSendNotificationSendNotificationEndpoint",
"requestBody": {
"x-name": "SendNotificationRequest",
"description": "",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/MyNotificationsApiEndpointsSendNotificationSendNotificationRequest"
}
}
},
"required": true,
"x-position": 1
},
"responses": {
"200": {
"description": "Success",
"content": {
"text/plain": {
"schema": {}
},
"application/json": {
"schema": {}
}
}
},
"400": {
"description": "Bad Request",
"content": {
"application/problem+json": {
"schema": {
"$ref": "#/components/schemas/FastEndpointsErrorResponse"
}
}
}
}
}
}
}
},
"components": {
"schemas": {
"FastEndpointsErrorResponse": {
"type": "object",
"additionalProperties": false,
"properties": {
"statusCode": {
"type": "integer",
"format": "int32",
"default": 400
},
"message": {
"type": "string",
"default": "One or more errors occurred!"
},
"errors": {
"type": "object",
"additionalProperties": {
"type": "array",
"items": {
"type": "string"
}
}
}
}
},
"MyNotificationsApiEndpointsSendNotificationSendNotificationRequest": {
"type": "object",
"additionalProperties": false,
"required": [
"request"
],
"properties": {
"request": {
"nullable": false,
"$ref": "#/components/schemas/MyNotificationsDomainModelModelsWebhookRequest"
}
}
},
"MyNotificationsDomainModelModelsWebhookRequest": {
"type": "object",
"additionalProperties": false,
"required": [
"content"
],
"properties": {
"username": {
"type": "string",
"nullable": true
},
"avatarUrl": {
"type": "string",
"nullable": true
},
"content": {
"type": "string",
"minLength": 1,
"nullable": false
},
"embeds": {
"type": "array",
"nullable": true,
"items": {
"$ref": "#/components/schemas/MyNotificationsDomainModelModelsEmbed"
}
}
}
},
"MyNotificationsDomainModelModelsEmbed": {
"type": "object",
"additionalProperties": false,
"properties": {
"author": {
"nullable": true,
"oneOf": [
{
"$ref": "#/components/schemas/MyNotificationsDomainModelModelsAuthor"
}
]
},
"title": {
"type": "string",
"nullable": true
},
"url": {
"type": "string",
"nullable": true
},
"description": {
"type": "string",
"nullable": true
},
"color": {
"type": "integer",
"format": "int32",
"nullable": true
},
"fields": {
"type": "array",
"nullable": true,
"items": {
"$ref": "#/components/schemas/MyNotificationsDomainModelModelsField"
}
},
"thumbnail": {
"nullable": true,
"oneOf": [
{
"$ref": "#/components/schemas/MyNotificationsDomainModelModelsUrlObject"
}
]
},
"image": {
"nullable": true,
"oneOf": [
{
"$ref": "#/components/schemas/MyNotificationsDomainModelModelsUrlObject"
}
]
},
"footer": {
"nullable": true,
"oneOf": [
{
"$ref": "#/components/schemas/MyNotificationsDomainModelModelsFooter"
}
]
}
}
},
"MyNotificationsDomainModelModelsAuthor": {
"type": "object",
"additionalProperties": false,
"properties": {
"name": {
"type": "string",
"nullable": true
},
"url": {
"type": "string",
"nullable": true
},
"iconUrl": {
"type": "string",
"nullable": true
}
}
},
"MyNotificationsDomainModelModelsField": {
"type": "object",
"additionalProperties": false,
"properties": {
"name": {
"type": "string",
"nullable": true
},
"value": {
"type": "string",
"nullable": true
},
"inline": {
"type": "boolean",
"nullable": true
}
}
},
"MyNotificationsDomainModelModelsUrlObject": {
"type": "object",
"additionalProperties": false,
"properties": {
"url": {
"type": "string",
"nullable": true
}
}
},
"MyNotificationsDomainModelModelsFooter": {
"type": "object",
"additionalProperties": false,
"properties": {
"text": {
"type": "string",
"nullable": true
},
"iconUrl": {
"type": "string",
"nullable": true
}
}
}
},
"securitySchemes": {
"JWTBearerAuth": {
"type": "http",
"description": "Enter a JWT token to authorize the requests...",
"scheme": "Bearer",
"bearerFormat": "JWT"
}
}
}
}- Docker and Docker Compose installed on your machine.
- Clone the repository and navigate to the project directory.
git clone https://github.com/git-df/dotnet-MyNotifications.git
cd dotnet-MyNotifications- Configure environment variables
-
Required:
- DiscordOptions__WebhookUrl (for mn.sender) - Webhook URL Documentation of discord webhooks
-
Optional:
- RABBITMQ_DEFAULT_USER (mn.rabbitmq) - RabbitMQ user name
- RABBITMQ_DEFAULT_PASS (mn.rabbitmq) - RabbitMQ user password
- POSTGRES_USER (mn.database) - Database user name
- POSTGRES_PASSWORD (mn.database) - Database user password
- POSTGRES_DB (mn.database) - Database name
- ConnectionStrings__DefaultConnection (mn.database.migrator) - Database connection string
- RabbitMqOptions__HostUri (mn.api) - RabbitMQ connection uri (amqp://name:password@host:5672)
- ConnectionStrings__DefaultConnection (mn.api) - Database connection string
- RabbitMqOptions__HostUri (mn.sender) - RabbitMQ connection uri (amqp://name:password@host:5672)
- ConnectionStrings__DefaultConnection (mn.sender) - Database connection string
- Run Docker Compose
docker-compose up --build -d- Go to swagger GUI
http://localhost:8080/swagger/index.html