Skip to content

Commit

Permalink
update included err-backend-cisco-webex-teams to 1.4.0 release
Browse files Browse the repository at this point in the history
  • Loading branch information
Mike Holloway committed Apr 10, 2019
1 parent 7317c78 commit 7f24cb4
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 4 deletions.
2 changes: 1 addition & 1 deletion docker-compose-swarmstack.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ configs:

services:
errbot:
image: swarmstack/errbot-docker
image: swarmstack/errbot-docker:5.2.0
configs:
- source: errbot_config
target: /err/config.py
Expand Down
2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ configs:

services:
errbot:
image: swarmstack/errbot-docker
image: swarmstack/errbot-docker:5.2.0
configs:
- source: errbot_config
target: /err/config.py
Expand Down
52 changes: 50 additions & 2 deletions local_backends/err-backend-cisco-webex-teams/CiscoWebexTeams.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,19 @@
import logging
import uuid
import websockets
import string
import random
import os
from markdown import markdown

from errbot.core import ErrBot
from errbot.backends.base import Message, Person, Room, RoomOccupant, OFFLINE, RoomDoesNotExistError
from errbot.backends.base import Message, Person, Room, RoomOccupant, OFFLINE, RoomDoesNotExistError, Stream
from errbot import rendering

import webexteamssdk

__version__="1.4.0"

log = logging.getLogger('errbot.backends.CiscoWebexTeams')

CISCO_WEBEX_TEAMS_MESSAGE_SIZE_LIMIT = 7439
Expand All @@ -24,7 +29,7 @@
"deviceType" : "DESKTOP",
"localizedModel": "python",
"model" : "python",
"name" : "python-webex-teams-client",
"name" : f"python-webex-teams-client-{''.join(random.choice(string.ascii_uppercase + string.digits) for _ in range(5))}",
"systemName" : "python-webex-teams-client",
"systemVersion" : "0.1"
}
Expand Down Expand Up @@ -523,6 +528,47 @@ def send_message(self, mess):
else:
self.webex_teams_api.messages.create(roomId=mess.to.room.id, text=mess.body, markdown=md)

def _teams_upload(self, stream):
"""
Performs an upload defined in a stream
:param stream: Stream object
:return: None
"""

try:
stream.accept()
log.exception(f'Upload of {stream.raw.name} to {stream.identifier} has started.')

if type(stream.identifier) == CiscoWebexTeamsPerson:
self.webex_teams_api.messages.create(toPersonId=stream.identifier.id, files=[stream.raw.name])
else:
self.webex_teams_api.messages.create(roomId=stream.identifier.room.id, files=[stream.raw.name])

stream.success()
log.exception(f'Upload of {stream.raw.name} to {stream.identifier} has completed.')

except Exception:
stream.error()
log.exception(f'Upload of {stream.raw.name} to {stream.identifier} has failed.')

finally:
stream.close()

def send_stream_request(self, identifier, fsource, name='file', size=None, stream_type=None):
"""
Send a file to Cisco Webex Teams
:param user: is the identifier of the person you want to send it to.
:param fsource: is a file object you want to send.
:param name: is an optional filename for it.
:param size: not supported in Webex Teams backend
:param stream_type: not supported in Webex Teams backend
"""
log.debug(f'Requesting upload of {fsource.name} to {identifier}.')
stream = Stream(identifier, fsource, name, size, stream_type)
self.thread_pool.apply_async(self._teams_upload, (stream,))
return stream

def build_reply(self, mess, text=None, private=False, threaded=False):
"""
Build a reply in the format expected by errbot by swapping the to and from source and destination
Expand Down Expand Up @@ -563,6 +609,8 @@ async def _run():
}
await ws.send(json.dumps(msg))

self.reset_reconnection_count()

while True:
message = await ws.recv()
logging.debug("WebSocket Received Message(raw): %s\n" % message)
Expand Down

0 comments on commit 7f24cb4

Please sign in to comment.