Metadata-Version: 2.4
Name: fcm-notifier
Version: 0.2.4
Summary: Сервис отправки push-уведомлений через FCM
Author-email: BARS Group <education_dev@bars.group>
Project-URL: Homepage, https://stash.bars-open.ru/projects/EDUBASE/repos/fcm-notifier/browse
Project-URL: Repository, https://stash.bars-open.ru/scm/edubase/fcm-notifier.git
Classifier: Development Status :: 3 - Alpha
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: MIT License
Classifier: Natural Language :: Russian
Classifier: Operating System :: POSIX
Classifier: Operating System :: MacOS
Classifier: Operating System :: Unix
Requires-Python: >=3.9
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: click>=8.1.3
Requires-Dist: redis>=3.5.3
Requires-Dist: firebase-admin==6.2.0
Provides-Extra: dev
Requires-Dist: isort==5.12.0; extra == "dev"
Requires-Dist: ruff==0.12.1; extra == "dev"
Requires-Dist: flake8<7,>=4.0.1; extra == "dev"
Requires-Dist: pytest<8,>=3.2.5; extra == "dev"
Requires-Dist: pytest-cov<5; extra == "dev"
Provides-Extra: docs
Requires-Dist: sphinx<7.5,>=7; extra == "docs"
Requires-Dist: sphinx-autodoc-typehints<2.5,>=2; extra == "docs"
Requires-Dist: myst-parser<3.2,>=3; extra == "docs"
Requires-Dist: sphinx_design<0.7,>=0.6; extra == "docs"
Dynamic: license-file

# Сервис по отправке push-уведомлений через Firebase Cloud Messaging

## Общее описание

fcm-notifier представляет собой сервис, который отдельно запускается в окружении РИС и с заданной 
периодичностью забирает накопившиеся сообщения из очереди, которые пачкой (до 500 штук) отправляет 
на мобильные устройства через FCM backend используя Firebase Admin SDK.

![](img/fcm-notifier-scheme.png)

## Настройка сервиса

Для работы сервиса необходимо в переменных окружения задать две переменные:

Путь до JSON-файла содержащего приватный ключ для доступа к сервисам Google:

    export GOOGLE_APPLICATION_CREDENTIALS=/opt/bars/fcm-notifier/mydiary.json

Путь до директории содержащей файл конфигурации сервиса:

    export FCM_NOTIFIER_CONFIG_DIR=/opt/bars/fcm-notifier/

Файл конфигурации fcm_notifier.conf:

```ini
[redis]
REDIS_HOST = 127.0.0.1
REDIS_PORT = 6379
REDIS_DB = 12
REDIS_PASSWORD =

[logging]
LEVEL = INFO
```

## Запуск сервиса

    $ fcm-notifier worker

## Использование очереди сообщений в РИС

Добавление сообщения в очередь:
```python
from fcm_notifier.helpers import get_redis_connection
from fcm_notifier.notification import Notification, NotificationPayload
from fcm_notifier.queue import RedisQueue


queue = RedisQueue(connection=get_redis_connection())

notification = Notification(
    payload=NotificationPayload(
        title='Test message!',
        body='Message body',
    ),
    token='dsufZwUdSFaeIGFt77aMwm:APA91bHQje7R...',
)

queue.enqueue_notification(notification)
```
