Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
A
AlekSIS-Core
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Terraform modules
Monitor
Service Desk
Analyze
Contributor analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
AlekSIS®
Official
AlekSIS-Core
Commits
d0ba42f0
Verified
Commit
d0ba42f0
authored
5 years ago
by
Nik | Klampfradler
Browse files
Options
Downloads
Patches
Plain Diff
Implement SMS sending for notifications
parent
2f49ce1b
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!137
Generalise notifications and implement SMS notifications
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
aleksis/core/templates/sms/notification.txt
+1
-0
1 addition, 0 deletions
aleksis/core/templates/sms/notification.txt
aleksis/core/util/notifications.py
+31
-0
31 additions, 0 deletions
aleksis/core/util/notifications.py
with
32 additions
and
0 deletions
aleksis/core/templates/sms/notification.txt
0 → 100644
+
1
−
0
View file @
d0ba42f0
🔔 {{ notification.sender }}: {{ notification.description }} · {{ notification.link }}
This diff is collapsed.
Click to expand it.
aleksis/core/util/notifications.py
+
31
−
0
View file @
d0ba42f0
"""
Utility code for notification system
"""
from
typing
import
Sequence
from
django.conf
import
settings
from
django.template.loader
import
get_template
from
django.utils.translation
import
gettext_lazy
as
_
from
constance
import
config
from
templated_email
import
send_templated_mail
try
:
from
twilio.rest
import
Client
as
TwilioClient
except
ImportError
:
TwilioClient
=
None
from
..models
import
Notification
from
.core_helpers
import
celery_optional
def
send_templated_sms
(
template_name
:
str
,
from_number
:
str
,
recipient_list
:
Sequence
[
str
],
context
:
dict
):
"""
Render a plan-text template and send via SMS to all recipients.
"""
template
=
get_template
(
template_name
)
text
=
template
.
render
(
context
)
client
=
TwilioClient
(
settings
.
TWILIO_SID
,
settings
.
TWILIO_TOKEN
)
for
recipient
in
recipient_list
:
client
.
messages
.
create
(
body
=
text
,
to
=
recipient
,
from_
=
from_number
)
def
_send_notification_email
(
notification
:
Notification
,
template
:
str
=
"
notification
"
)
->
None
:
context
=
{
"
notification
"
:
notification
,
...
...
@@ -23,6 +41,19 @@ def _send_notification_email(notification: Notification, template: str = "notifi
)
def
_send_notification_sms
(
notification
:
Notification
,
template
:
str
=
"
sms/notification.txt
"
)
->
None
:
context
=
{
"
notification
"
:
notification
,
"
notification_user
"
:
notification
.
person
.
adressing_name
,
}
send_templated_sms
(
template_name
=
template
,
from_number
=
settings
.
TWILIO_CALLER_ID
,
recipient_list
=
[
notification
.
person
.
mobile_number
],
context
=
context
,
)
# Mapping of channel id to name and two functions:
# - Check for availability
# - Send notification through it
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment