As an admin I would like to send manually the notifications to be shown under the bell icon on the apps panel. Only admin should be able to send the announcements.
So, I’ve installed announcementcenter app. Created a post there, however it is shown only in Activities tab.
USERS=(sudo -u www-data php occ ldap:search "" | rev | cut -d " " -f1 | rev | sed 's/(//g' | sed 's/)//g') )
for element in "${USERS[@]}"; do
eval 'sudo -u www-data php occ notification:generate' $element "'This is a notification for all users that will pop-up in any browser, be visible on device lock screens and will show under the notifications icon (the bell)'" $SILENT; done
This Piece of code lists all users (I am only interested in hitting users I get from my LDAP and not NC only users) and then sends the same notification to all those users.
The syntax is as follows for sending a notification for a single user:
This is great that you shared it
For some, it might seem like a small thing, but when you’re dealing with automation or need to notify multiple users at once, having a concrete example like this can save a lot of time and effort.
It’s clear you put some thought into it, and it’s definitely helpful — even for me
Posts like this make a real difference and show the true value of the community.
Well not in one command. However you can use the same method to get a list of users in a group, and then in same way as above, iterate that list in a for loop.
occ group:list
To get all groups including members.
Unfortunately this is also the only CLI command that will show you members of the groups, and as such, you will need to do some work with your array manaipulation to get the group and members of your choosing. However when that is done, then yes, you can use that same for loop method I did above.
A little helpfull addition to your output, can be to output it as JSON:
sudo -u www-data php occ group:list --output=json
At least this way you can use json tricks to get the excact member list you look for.
The absolutely most effecient way to work with json nativaly in the CLI is to install jq.
This one tested and verified as getting the intended JSON items.
To get the full, functioning BASH code:
USERS=( $(sudo -u www-data php /var/www/nextcloud/occ group:list --output=json | jq -r '.MyGroup' | sed -e 's/\[//g' -e 's/\]//g' -e 's/\,//g' -e 's|["'\'']||g') )
for element in "${USERS[@]}"; do
eval 'sudo -u www-data php occ notification:generate' $element "'This is a notification for all users that will pop-up in any browser, be visible on device lock screens and will show under the notifications icon (the bell)'" $SILENT; done
done
So this is an example of a fully working code where you can inout which group is in scope as a variable:
GROUP="MyGroup"
for element in $(sudo -u www-data php /var/www/nextcloud/occ group:list --output=json | jq -r ".$GROUP" | sed -e 's/\[//g' -e 's/\]//g' -e 's/\,//g' -e 's|["'\'']||g'); do
eval 'sudo -u www-data php occ notification:generate' $element "'This is a notification for all users that will pop-up in any browser, be visible on device lock screens and will show under the notifications icon (the bell)'" $SILENT;
done
@SmallOne How to specify that and send on behalf of admin? Eg, I am an admin, I created the message in applicationcenter, and I do not see that message under the bell icon.
@Kerasit Can I ask you to adjust the code in order I can read the text from a file and place it in the notification, ideally formatted with paragraphs?
@Kerasit I tried to go the same way, and in my case I’ve got errors, if the text value is a big text with paragraphs and URLS… I do not know whtether text formatting is supported in the notification at all.
Notifications is an app. If you findes the app and go to the GitHub repo of the app, you can find the documentation. There are a lot of limitations with the notification feature. First of all then the long text support maximum 4000 characters. The short, obviously way less.
You cannot use any kind of formatting. The text you enters are printed in a span object, så no breakline, Italic, bold, colors and whatever. Any character is literally printed as if escaped.