Skip to content
This repository has been archived by the owner on Aug 22, 2019. It is now read-only.

Commit

Permalink
formatting improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
tmbo committed Aug 21, 2018
1 parent af16179 commit a5927b0
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 16 deletions.
34 changes: 21 additions & 13 deletions rasa_core/channels/mattermost.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

from flask import Blueprint, request, jsonify, make_response
from mattermostwrapper import MattermostAPI
from typing import Text

from rasa_core.channels.channel import UserMessage, OutputChannel, InputChannel

Expand All @@ -26,6 +27,7 @@ def __init__(self, url, team, user, pw, bot_channel):
self.user = user
self.pw = pw
self.bot_channel = bot_channel

super(MattermostBot, self).__init__(url, team)
super(MattermostBot, self).login(user, pw)

Expand All @@ -36,18 +38,19 @@ def send_text_message(self, recipient_id, message):


class MattermostInput(InputChannel):
"""Mattermost input channel implemenation. Based on the HTTPInputChannel."""
"""Mattermost input channel implemenation."""

@classmethod
def name(cls):
return "mattermost"

def __init__(self, url, team, user, pw):
# type: (Text, Text) -> None
# type: (Text, Text, Text, Text) -> None
"""Create a Mattermost input channel.
Needs a couple of settings to properly authenticate and validate
messages.
:param url: Your Mattermost team url including /v4 example https://mysite.example.com/api/v4
:param url: Your Mattermost team url including /v4 example
https://mysite.example.com/api/v4
:param team: Your mattermost team name
Expand All @@ -72,20 +75,25 @@ def webhook():
request.get_data()
if request.json:
output = request.json
# splitting to get rid of the @botmention trigger we are using for this
# splitting to get rid of the @botmention
# trigger we are using for this
text = output['text'].split(" ", 1)
text = text[1]
sender_id = output['user_id']
self.bot_channel = output['channel_id']
try:
out_channel = MattermostBot(self.url, self.team, self.user, self.pw, self.bot_channel)
user_msg = UserMessage(text, out_channel, sender_id)
on_new_message(user_msg)
except Exception as e:
logger.error("Exception when trying to handle "
"message.{0}".format(e))
logger.error(e, exc_info=True)
pass
try:
out_channel = MattermostBot(self.url,
self.team,
self.user,
self.pw,
self.bot_channel)
user_msg = UserMessage(text, out_channel, sender_id)
on_new_message(user_msg)
except Exception as e:
logger.error("Exception when trying to handle "
"message.{0}".format(e))
logger.error(e, exc_info=True)
pass
return make_response()

return mattermost_webhook
5 changes: 2 additions & 3 deletions rasa_core/processor.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,9 +147,8 @@ def has_message_after_reminder(tracker):
it might be better to cancel it."""

for e in reversed(tracker.events):
if isinstance(e,
ReminderScheduled) and e.name == \
reminder_event.name:
if (isinstance(e, ReminderScheduled) and
e.name == reminder_event.name):
return False
elif isinstance(e, UserUttered):
return True
Expand Down

0 comments on commit a5927b0

Please sign in to comment.