How to use the errbot.backends.base.Message function in errbot

To help you get started, we’ve selected a few errbot examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github sinkingpoint / GHC-Errbot / hangouts_chat.py View on Github external
log.warning('Received 0 eventTime from message')

        send_name = sender_blob.get('name', '')
        thread_name = data.get('message', {}).get('thread', {}).get('name', '')
        body_length = len(message_body)
        message_id = "{}{}{}{}".format(time, send_name, thread_name, body_length)
        cached = self.message_cache.get(message_id)
        if cached is not None:
            return
        self.message_cache[message_id] = True

        context = {
            'space_id': data['space']['name'],
            'thread_id': data['message']['thread']['name']
        }
        msg = Message(body=message_body.strip(), frm=sender, extras=context)
        is_dm = data['message']['space']['type'] == 'DM'
        if is_dm:
            msg.to = self.bot_identifier
        self.callback_message(msg)
github errbotio / err-backend-gitter / gitter.py View on Github external
def stream(self):
        r = self.backend.streamAPIRequest('rooms/%s/chatMessages' % self.room.idd)
        log.debug("connected %s" % self.room.name)

        try:
            self.reset_reconnection_count()
            for line in r.iter_lines(chunk_size=1):  # it fails with anything else than 1.
                if line.strip():
                    json_message = json.loads(line.decode('utf-8'))
                    from_user = json_message['fromUser']
                    log.debug("Raw message from room %s: %s" % (self.room.name, json_message))
                    m = Message(json_message['text'],
                                extras={'id': json_message['id']})
                    if self.room._uri == from_user['url']:
                        m.to = self.backend.bot_identifier
                    else:
                        m.to = self.room
                        m.extras['url'] = 'https://gitter.im/%s?at=%s' % (
                            self.room.uri, m.extras['id'])
                    m.frm = GitterRoomOccupant.build_from_json(self.room, from_user)
                    self.backend.callback_message(m)
                else:
                    log.debug('Received keep-alive on %s', self.room.name)
        except:
            log.exception('An exception occured while streaming the room: ')
github errbotio / errbot / errbot / backends / text.py View on Github external
def serve_forever(self):
        self.readline_support()

        if not self._rooms:
            # artificially join a room if None were specified.
            self.query_room('#testroom').join()

        if self.demo_mode:
            # disable the console logging once it is serving in demo mode.
            root = logging.getLogger()
            root.removeHandler(console_hdlr)
            root.addHandler(logging.NullHandler())
        self.connect_callback()  # notify that the connection occured
        self.callback_presence(Presence(identifier=self.user, status=ONLINE))

        self.send_message(Message(INTRO))

        try:
            while True:

                if self._inroom:
                    frm = TextOccupant(self.user, self.rooms[0])
                    to = self.rooms[0]
                else:
                    frm = self.user
                    to = self.bot_identifier

                print()
                full_msg = ''
                while True:
                    prompt = '[␍] ' if full_msg else '>>> '
                    if ANSI or self.demo_mode:
github errbotio / errbot / errbot / backends / base.py View on Github external
return isinstance(self.to, Room)

    @property
    def is_threaded(self) -> bool:
        return self._parent is not None

    @property
    def partial(self) -> bool:
        return self._partial

    @partial.setter
    def partial(self, partial):
        self._partial = partial


class Card(Message):
    """
        Card is a special type of preformatted message. If it matches with a backend similar concept like on
        Slack or Hipchat it will be rendered natively, otherwise it will be sent as a regular message formatted with
        the card.md template.
    """

    def __init__(self,
                 body: str = '',
                 frm: Identifier = None,
                 to: Identifier = None,
                 parent: Message = None,
                 summary: str = None,
                 title: str = '',
                 link: str = None,
                 image: str = None,
                 thumbnail: str = None,
github errbotio / errbot / errbot / backends / graphic.py View on Github external
def build_message(self, text):
        msg = Message(text)
        msg.frm = self.bot_identifier
        return msg  # rebuild a pure html snippet to include directly in the console html
github errbotio / errbot / errbot / backends / irc.py View on Github external
def _pubmsg(self, e, notice=False):
        msg = Message(e.arguments[0], extras={'notice': notice})
        room_name = e.target
        if room_name[0] != '#' and room_name[0] != '$':
            raise Exception('[%s] is not a room' % room_name)
        room = IRCRoom(room_name, self.bot)
        msg.frm = IRCRoomOccupant(e.source, room)
        msg.to = room
        msg.nick = msg.frm.nick  # FIXME find the real nick in the channel
        self.bot.callback_message(msg)

        possible_mentions = re.findall(IRC_NICK_REGEX, e.arguments[0])
        room_users = self.channels[room_name].users()
        mentions = filter(lambda x: x in room_users, possible_mentions)
        if mentions:
            mentions = [self.bot.build_identifier(mention) for mention in mentions]
            self.bot.callback_mention(msg, mentions)
github errbotio / errbot / errbot / backends / tox.py View on Github external
def on_group_message(self, group_number, friend_group_number, message):
        log.debug('TOX: Group-%i User-%i: %s' % (group_number, friend_group_number, message))
        msg = Message(message, type_='groupchat')
        msg.frm = ToxIdentifier(group_number=str(group_number), friend_group_number=str(friend_group_number))
        msg.to = self.backend.bot_identifier
        log.debug('TOX: callback with type = %s' % msg.type)
        self.backend.callback_message(msg)
github errbotio / errbot / errbot / backends / tox.py View on Github external
def on_friend_message(self, friend_number, message):
        msg = Message(message)
        msg.frm = self.friend_to_idd(friend_number)
        log.debug('TOX: %s: %s' % (msg.frm, message))
        msg.to = self.backend.bot_identifier
        self.backend.callback_message(msg)
github sinkingpoint / GHC-Errbot / hangouts_chat.py View on Github external
def build_reply(self, msg, text=None, private=False, threaded=False):
        response = Message(body=text, frm=msg.to, to=msg.frm, extras=msg.extras)
        return response