slack_bot.py 719 B

123456789101112131415161718192021222324252627282930313233343536
  1. import logging
  2. import slackclient
  3. import base
  4. import conf
  5. class SlackBot(base.Base):
  6. def __init__(self):
  7. self.client = slackclient.SlackClient(conf.SLACK_BOT_API_KEY)
  8. def _send(self, text):
  9. res = self.client.api_call(
  10. 'chat.postMessage',
  11. channel='voice_control',
  12. text=text
  13. )
  14. def success(self):
  15. self._send('Ok.')
  16. def failure(self, s=None):
  17. if s:
  18. self._send(s)
  19. else:
  20. self._send('Error.')
  21. def cancelled(self):
  22. self._send('Cancelled.')
  23. def tts(self, s):
  24. self._send(s)
  25. def text(self, s):
  26. self._send(s)
  27. def debug(self, s):
  28. self._send(s)