update message text, ignore errors for now

This commit is contained in:
Oliver Marks 2017-09-08 21:49:59 +01:00
parent 409f6651c3
commit d1d7ae7365
2 changed files with 29 additions and 59 deletions

View File

@ -69,15 +69,13 @@ def send_topic_update_email(sender, instance, **kwargs):
to=[user_email],
headers={'Reply-To': 'no-reply@maidstone-hackspace.org.uk'})
email.send()
matrix_message.delay('%s https://%s%s' % (
instance.topic.title,
matrix_message.delay('https://%s%s' % (
Site.objects.get_current().domain,
instance.topic.get_absolute_url()))
def wiki_article_updated(sender, instance, **kwargs):
matrix_message.delay('%s https://%s%s' % (
instance.title,
matrix_message.delay('https://%s%s' % (
Site.objects.get_current().domain,
instance.article.get_absolute_url()))

View File

@ -17,62 +17,34 @@ matrix_send_msg_url = matrix_url + "/rooms/%21{room}/send/m.room.message?access_
@shared_task
def matrix_message(message):
# login
details = {
"type":"m.login.password",
"user":settings.MATRIX_USER,
"password":settings.MATRIX_PASSWORD}
r0 = requests.post(matrix_login_url, json = details)
access_token = r0.json().get('access_token')
# we dont rely on theses, so ignore if it goes wrong
# TODO at least log that something has gone wrong
try:
# login
details = {
"type":"m.login.password",
"user":settings.MATRIX_USER,
"password":settings.MATRIX_PASSWORD}
r0 = requests.post(matrix_login_url, json = details)
access_token = r0.json().get('access_token')
# join room by id
url_params = {
'room': settings.MATRIX_ROOM,
'access_token': access_token}
url = matrix_join_room_id_url.format(**url_params)
r1 = requests.post(url)
# join room by id
url_params = {
'room': settings.MATRIX_ROOM,
'access_token': access_token}
url = matrix_join_room_id_url.format(**url_params)
r1 = requests.post(url)
# send message
url_params = {
"room": settings.MATRIX_ROOM,
"access_token": access_token}
url = matrix_send_msg_url.format(**url_params)
details = {
"msgtype": "m.text",
"body": "%s %s" % (settings.MSG_PREFIX, message)}
r2 = requests.post(url, json=details)
# send message
url_params = {
"room": settings.MATRIX_ROOM,
"access_token": access_token}
url = matrix_send_msg_url.format(**url_params)
details = {
"msgtype": "m.text",
"body": "%s %s" % (settings.MSG_PREFIX, message)}
r2 = requests.post(url, json=details)
except:
pass
return True
# url = "https://matrix.org/_matrix/client/r0/join/{room_alias}?access_token={access_token}".format(
# **{'access_token': access_token,
# 'room_alias': '#maidstone-hackspace:matrix.org'})
# response = requests.post(url)
# return import_feeds()
# url = "https://matrix.org/_matrix/client/r0/rooms/%21{room}:matrix.org/join?access_token={access_token}".format(
# **{'room': 'fmCpNwqgIiuwATlcdw',
# 'access_token': access_token})
# r = requests.get(url)
# fmCpNwqgIiuwATlcdw:matrix.org
#join room by id
# url = "https://matrix.org/_matrix/client/r0/rooms/%21{room}/join?access_token={access_token}".format(
# **{'room': 'fmCpNwqgIiuwATlcdw:matrix.org',
# 'access_token': access_token})
# response = requests.post(url)
# url = "https://matrix.org/_matrix/client/r0/rooms/%21{room}/send/m.room.message?access_token={access_token}".format(
# **{'room': 'fmCpNwqgIiuwATlcdw:matrix.org',
# 'access_token': access_token})
# details = {"msgtype":"m.text", "body":"poke from python"} #{"type":"m.login.password", "user":"oly", "password":""}
# r = requests.post(url, json = details)
# return r.json()
# url = "https://matrix.org/_matrix/client/r0/rooms/%21{room}/join?access_token={access_token}".format(
# **{'room': 'fmCpNwqgIiuwATlcdw:matrix.org',
# 'access_token': access_token})
# response = requests.post(url)