How to use the hangups.ChatMessageEvent function in hangups

To help you get started, we’ve selected a few hangups 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 hangoutsbot / hangoutsbot / hangupsbot / webbridge / __init__.py View on Github external
logger.info("{}:{}:repeat:{}".format(self.plugin_name, self.uid, passthru["norelay"]))

        user = event.user
        message = event.text
        image_id = None
        is_action = False

        if "original_request" not in passthru:
            """user has raised an event that needs to be repeated

            only the first handler to run will assign all the variables 
                we need for the other bridges to work"""

            logger.info("hangouts user raised an event, first seen by {}".format(self.plugin_name))

            if (hasattr(event, "conv_event") and isinstance(event.conv_event, ChatMessageEvent) and
                    any(a.type == 4 for a in event.conv_event._event.chat_message.annotation)):
                # This is a /me message sent from desktop Hangouts.
                is_action = True
                # The user's first name prefixes the message, so try to strip that.
                name = self._get_user_details(event.user).get("full_name")
                if name:
                    # We don't have a clear-cut first name, so try to match parts of names.
                    # Try the full name first, then split successive words off the end.
                    parts = name.split()
                    for pos in range(len(parts), 0, -1):
                        sub_name = " ".join(parts[:pos])
                        if message.startswith(sub_name):
                            message = message[len(sub_name) + 1:]
                            break
                    else:
                        # Couldn't match the user's name to the message text.
github davidedmundson / telepathy-hangups / hangups_demo.py View on Github external
def on_conversation_event(conv_event):
    global user_list
    if isinstance(conv_event, hangups.ChatMessageEvent):
        print ("conversation event:" + str(user_list.get_user(conv_event.user_id).full_name) + str(conv_event.text))
github matrix-hacks / matrix-puppet-hangouts / hangups_client.py View on Github external
def on_event(conv_event):
    global conv_list, event_queue
    #pprint(getmembers(conv_event))
    if isinstance(conv_event, hangups.ChatMessageEvent):
        conv = conv_list.get(conv_event.conversation_id)
        user = conv.get_user(conv_event.user_id)

        try:
            msgJson = json.dumps({
                'status':'success',
                'type':'message',
                'content':conv_event.text,
                'attachments': conv_event.attachments,
                'conversation_id': conv.id_,
                'conversation_name':get_conv_name(conv),
                'photo_url':user.photo_url,
                'user':user.full_name,
                'self_user_id':user_list._self_user.id_.chat_id,
                'user_id':{'chat_id':conv_event.user_id.chat_id, 'gaia_id':conv_event.user_id.gaia_id}
            })
github tdryer / hangups / examples / receive_messages.py View on Github external
def on_event(conv_event):
    if isinstance(conv_event, hangups.ChatMessageEvent):
        print('received chat message: {!r}'.format(conv_event.text))
github hangoutsbot / hangoutsbot / hangupsbot / hangupsbot.py View on Github external
def _on_event(self, conv_event):
        """Handle conversation events"""

        self._execute_hook("on_event", conv_event)

        if isinstance(conv_event, hangups.ChatMessageEvent):
            self.handle_chat_message(conv_event)

        elif isinstance(conv_event, hangups.MembershipChangeEvent):
            self.handle_membership_change(conv_event)

        elif isinstance(conv_event, hangups.RenameEvent):
            self.handle_rename(conv_event)
github xmikos / hangupsbot / hangupsbot / handlers / forwarding.py View on Github external
@handler.register(priority=7, event=hangups.ChatMessageEvent)
def handle_forward(bot, event):
    """Handle message forwarding"""
    # Test if message is not empty
    if not event.text:
        return

    # Test if message forwarding is enabled
    if not bot.get_config_suboption(event.conv_id, 'forwarding_enabled'):
        return

    # Test if there are actually any forwarding destinations
    forward_to_list = bot.get_config_suboption(event.conv_id, 'forward_to')
    if not forward_to_list:
        return

    # Prepare attachments
github xmikos / hangupsbot / hangupsbot / handlers / autoreplies.py View on Github external
@handler.register(priority=7, event=hangups.ChatMessageEvent)
def handle_autoreply(bot, event):
    """Handle autoreplies to keywords in messages"""
    # Test if message is not empty
    if not event.text:
        return

    # Test if autoreplies are enabled
    if not bot.get_config_suboption(event.conv_id, 'autoreplies_enabled'):
        return

    # Test if there are actually any autoreplies
    autoreplies_list = bot.get_config_suboption(event.conv_id, 'autoreplies')
    if not autoreplies_list:
        return

    for kwds, sentence in autoreplies_list:
github hangoutsbot / hangoutsbot / hangupsbot / plugins / noop_xmikos.py View on Github external
@handler.register(priority=5, event=hangups.ChatMessageEvent)
def _handle_nothing_xmikos(bot, event):
    print("xmikosbot: i handled nothing, but a message just went by!")
github xmikos / hangupsbot / hangupsbot / handlers / __init__.py View on Github external
def __init__(self, bot, conv_event):
        self.conv_event = conv_event
        self.conv_id = conv_event.conversation_id
        self.conv = bot._conv_list.get(self.conv_id)
        self.user_id = conv_event.user_id
        self.user = self.conv.get_user(self.user_id)
        self.timestamp = conv_event.timestamp
        self.text = conv_event.text.strip() if isinstance(conv_event, hangups.ChatMessageEvent) else ''
github hangoutsbot / hangoutsbot / hangupsbot / event.py View on Github external
def __init__(self, bot, conv_event):
        super().__init__(bot)

        self.conv_event = conv_event
        self.conv_id = conv_event.conversation_id
        self.conv = self.bot._conv_list.get(self.conv_id)
        self.event_id = conv_event.id_
        self.user_id = conv_event.user_id
        self.user = self.conv.get_user(self.user_id)
        self.timestamp = conv_event.timestamp
        self.text = conv_event.text.strip() if isinstance(conv_event, hangups.ChatMessageEvent) else ''

        self.log()