forked from janvarev/Irene-Voice-Assistant
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
expose submit_active_interaction for non-skill plugins; add notificat…
…ion api plugin
- Loading branch information
1 parent
e194469
commit 9e7e3c1
Showing
3 changed files
with
89 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
""" | ||
Добавляет API для отправки/озвучивания простых уведомлений. | ||
""" | ||
|
||
from typing import Optional | ||
|
||
from irene.brain.abc import Brain, VAApiExt | ||
|
||
name = "notification_api" | ||
version = "0.1.0" | ||
|
||
_brain: Optional[Brain] = None | ||
|
||
|
||
def get_brain(nxt, *args, **kwargs): | ||
global _brain | ||
|
||
b = nxt(*args, **kwargs) | ||
if _brain is None: | ||
_brain = b | ||
return b | ||
|
||
|
||
def register_fastapi_endpoints(router, *_args, **_kwargs) -> None: | ||
from fastapi import APIRouter, Body, HTTPException | ||
from pydantic import BaseModel, Field | ||
|
||
r: APIRouter = router | ||
|
||
class NotificationModel(BaseModel): | ||
text: str = Field( | ||
title="Текст уведомления" | ||
) | ||
|
||
@r.post('/notify', name="Отправка уведомления") | ||
def notify(notification: NotificationModel = Body()): | ||
if _brain is None: | ||
raise HTTPException(503, "Мозг не найден") | ||
|
||
def interaction(va: VAApiExt): | ||
va.say(notification.text) | ||
|
||
_brain.submit_active_interaction(interaction) |