Browse Source

[slack] Add hue username in bot's slack message for author context and update API UTs (#2058)

Harsh Gupta 4 years ago
parent
commit
a0296f53e8

+ 1 - 0
desktop/core/src/desktop/lib/botserver/api.py

@@ -50,6 +50,7 @@ def send_message(request):
   channel = request.POST.get('channel')
   message = request.POST.get('message')
 
+  message = '@' + (request.user.get_full_name() or request.user.username) + ': ' + message
   slack_response = _send_message(channel, message)
 
   return JsonResponse({

+ 2 - 2
desktop/core/src/desktop/lib/botserver/api_tests.py

@@ -75,9 +75,9 @@ class TestApi(object):
          "ok": True,
       }
 
-      response = self.client.post(reverse('botserver.api.send_message'), {'channel': 'channel-1', 'message': 'some message'})
+      response = self.client.post(reverse('botserver.api.send_message'), {'channel': 'channel-1', 'message': 'message with link'})
       data = json.loads(response.content)
 
       assert_equal(200, response.status_code)
-      chat_postMessage.assert_called_with(channel='channel-1', text='some message')
+      chat_postMessage.assert_called_with(channel='channel-1', text='@api_user: message with link')
       assert_true(data.get('ok'))