mirror of
https://github.com/open-webui/open-webui.git
synced 2025-12-12 12:25:20 +00:00
fix: send notification
This commit is contained in:
parent
c3ea4feca5
commit
1077b2ac8b
5 changed files with 33 additions and 32 deletions
|
|
@ -220,7 +220,7 @@ class UsersTable:
|
||||||
filter: Optional[dict] = None,
|
filter: Optional[dict] = None,
|
||||||
skip: Optional[int] = None,
|
skip: Optional[int] = None,
|
||||||
limit: Optional[int] = None,
|
limit: Optional[int] = None,
|
||||||
) -> UserListResponse:
|
) -> dict:
|
||||||
with get_db() as db:
|
with get_db() as db:
|
||||||
query = db.query(User)
|
query = db.query(User)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -200,14 +200,11 @@ async def send_notification(name, webui_url, channel, message, active_user_ids):
|
||||||
users = get_users_with_access("read", channel.access_control)
|
users = get_users_with_access("read", channel.access_control)
|
||||||
|
|
||||||
for user in users:
|
for user in users:
|
||||||
if user.id in active_user_ids:
|
if user.id not in active_user_ids:
|
||||||
continue
|
|
||||||
else:
|
|
||||||
if user.settings:
|
if user.settings:
|
||||||
webhook_url = user.settings.ui.get("notifications", {}).get(
|
webhook_url = user.settings.ui.get("notifications", {}).get(
|
||||||
"webhook_url", None
|
"webhook_url", None
|
||||||
)
|
)
|
||||||
|
|
||||||
if webhook_url:
|
if webhook_url:
|
||||||
await post_webhook(
|
await post_webhook(
|
||||||
name,
|
name,
|
||||||
|
|
@ -221,6 +218,8 @@ async def send_notification(name, webui_url, channel, message, active_user_ids):
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|
||||||
|
return True
|
||||||
|
|
||||||
|
|
||||||
@router.post("/{id}/messages/post", response_model=Optional[MessageModel])
|
@router.post("/{id}/messages/post", response_model=Optional[MessageModel])
|
||||||
async def post_new_message(
|
async def post_new_message(
|
||||||
|
|
@ -305,8 +304,8 @@ async def post_new_message(
|
||||||
|
|
||||||
active_user_ids = get_user_ids_from_room(f"channel:{channel.id}")
|
active_user_ids = get_user_ids_from_room(f"channel:{channel.id}")
|
||||||
|
|
||||||
background_tasks.add_task(
|
async def background_handler():
|
||||||
send_notification,
|
await send_notification(
|
||||||
request.app.state.WEBUI_NAME,
|
request.app.state.WEBUI_NAME,
|
||||||
request.app.state.config.WEBUI_URL,
|
request.app.state.config.WEBUI_URL,
|
||||||
channel,
|
channel,
|
||||||
|
|
@ -314,6 +313,8 @@ async def post_new_message(
|
||||||
active_user_ids,
|
active_user_ids,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
background_tasks.add_task(background_handler)
|
||||||
|
|
||||||
return MessageModel(**message.model_dump())
|
return MessageModel(**message.model_dump())
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
log.exception(e)
|
log.exception(e)
|
||||||
|
|
|
||||||
|
|
@ -130,9 +130,10 @@ def has_access(
|
||||||
# Get all users with access to a resource
|
# Get all users with access to a resource
|
||||||
def get_users_with_access(
|
def get_users_with_access(
|
||||||
type: str = "write", access_control: Optional[dict] = None
|
type: str = "write", access_control: Optional[dict] = None
|
||||||
) -> List[UserModel]:
|
) -> list[UserModel]:
|
||||||
if access_control is None:
|
if access_control is None:
|
||||||
return Users.get_users()
|
result = Users.get_users()
|
||||||
|
return result.get("users", [])
|
||||||
|
|
||||||
permission_access = access_control.get(type, {})
|
permission_access = access_control.get(type, {})
|
||||||
permitted_group_ids = permission_access.get("group_ids", [])
|
permitted_group_ids = permission_access.get("group_ids", [])
|
||||||
|
|
|
||||||
|
|
@ -52,12 +52,12 @@
|
||||||
const item = filteredItems[index];
|
const item = filteredItems[index];
|
||||||
if (!item) return;
|
if (!item) return;
|
||||||
|
|
||||||
// Add the "U:", "A:" or "C:" prefix to the id
|
// Add the "U:", "M:" or "C:" prefix to the id
|
||||||
// and also append the label after a pipe |
|
// and also append the label after a pipe |
|
||||||
// so that the mention renderer can show the label
|
// so that the mention renderer can show the label
|
||||||
if (item)
|
if (item)
|
||||||
command({
|
command({
|
||||||
id: `${item.type === 'user' ? 'U' : item.type === 'model' ? 'A' : 'C'}:${item.id}|${item.label}`,
|
id: `${item.type === 'user' ? 'U' : item.type === 'model' ? 'M' : 'C'}:${item.id}|${item.label}`,
|
||||||
label: item.label
|
label: item.label
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -53,8 +53,8 @@
|
||||||
} else if (triggerChar === '@') {
|
} else if (triggerChar === '@') {
|
||||||
if (idType === 'U') {
|
if (idType === 'U') {
|
||||||
// User
|
// User
|
||||||
} else if (idType === 'A') {
|
} else if (idType === 'M') {
|
||||||
// Agent/assistant/ai model
|
// Model
|
||||||
const model = $models.find((m) => m.id === id);
|
const model = $models.find((m) => m.id === id);
|
||||||
if (model) {
|
if (model) {
|
||||||
label = model.name;
|
label = model.name;
|
||||||
|
|
@ -77,9 +77,8 @@
|
||||||
if (idType === 'U') {
|
if (idType === 'U') {
|
||||||
// Open user profile
|
// Open user profile
|
||||||
console.log('Clicked user mention', id);
|
console.log('Clicked user mention', id);
|
||||||
} else if (idType === 'A') {
|
} else if (idType === 'M') {
|
||||||
// Open agent/assistant/ai model profile
|
console.log('Clicked model mention', id);
|
||||||
console.log('Clicked agent mention', id);
|
|
||||||
await goto(`/?model=${id}`);
|
await goto(`/?model=${id}`);
|
||||||
}
|
}
|
||||||
} else if (triggerChar === '#') {
|
} else if (triggerChar === '#') {
|
||||||
|
|
@ -101,15 +100,15 @@
|
||||||
</span>
|
</span>
|
||||||
</LinkPreview.Trigger>
|
</LinkPreview.Trigger>
|
||||||
|
|
||||||
|
{#if triggerChar === '@' && idType === 'U'}
|
||||||
<LinkPreview.Content
|
<LinkPreview.Content
|
||||||
class="w-full max-w-[260px] rounded-2xl border border-gray-100 dark:border-gray-800 z-50 bg-white dark:bg-gray-850 dark:text-white shadow-lg transition"
|
class="w-full max-w-[260px] rounded-2xl border border-gray-100 dark:border-gray-800 z-50 bg-white dark:bg-gray-850 dark:text-white shadow-lg transition"
|
||||||
side="top"
|
side="top"
|
||||||
align="start"
|
align="start"
|
||||||
sideOffset={6}
|
sideOffset={6}
|
||||||
>
|
>
|
||||||
{#if triggerChar === '@' && idType === 'U'}
|
|
||||||
<UserStatus {id} />
|
<UserStatus {id} />
|
||||||
{/if}
|
|
||||||
<!-- <div class="flex space-x-4">HI</div> -->
|
<!-- <div class="flex space-x-4">HI</div> -->
|
||||||
</LinkPreview.Content>
|
</LinkPreview.Content>
|
||||||
|
{/if}
|
||||||
</LinkPreview.Root>
|
</LinkPreview.Root>
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue