Giter VIP home page Giter VIP logo

hangupsbot's Introduction

HangupsBot

Bot for Google Hangouts

Requirements

Usage

Run hangupsbot --help to see all available options. Start HangupsBot by running hangupsbot.

You can configure basic settings in config.json file. This file will be copied to user data directory (e.g. ~/.local/share/hangupsbot/ on Linux) after first start of HangupsBot.

The first time you start HangupsBot, you will be prompted to open a link in your web browser where you log into your Google account. After logging in and clicking on "SIGN IN", you should see authorization code. Copy this code to clipboard and paste it into HangupsBot to complete the process. Your credentials will only be sent to Google, and only OAuth 2 refresh token will be stored locally.

Help

usage: hangupsbot [-h] [-d] [--log LOG] [--token TOKEN] [--config CONFIG]
                  [--version]

optional arguments:
  -h, --help       show this help message and exit
  -d, --debug      log detailed debugging messages (default: False)
  --log LOG        log file path (default:
                   ~/.local/share/hangupsbot/hangupsbot.log)
  --token TOKEN    OAuth refresh token storage path (default:
                   ~/.local/share/hangupsbot/refresh_token.txt)
  --config CONFIG  config storage path (default:
                   ~/.local/share/hangupsbot/config.json)
  --version        show program's version number and exit

Features (event handlers)

  • autoreplies - automatically reply to specified keywords in messages
  • commands - run /bot commands (type /bot help for list of available commands)
  • forwarding - forward messages from one conversation to another
  • membership - watch conversations for added/removed users
  • rename - watch for renamed conversations (only example plugin for now)

Development

You can extend HangupsBot in two ways - by writing handlers or commands plugins. Every Python file (which doesn't start with _) in handlers and commands directories is loaded automatically.

Handlers

Functions in plugins can be registered as event handlers by decorating them with @handler.register(priority=10, event=None) decorator.

If event parameter is None (default), all event types are forwarded to handler. If you want to handle only some specific type of event, you can set event to hangups.ChatMessageEvent, hangups.MembershipChangeEvent or hangups.RenameEvent.

You can change priority of handler by specifying priority parameter (default is 10). A lower number means higher priority. If you raise StopEventHandling exception in your handler, current event will not be handled by any other handler.

Commands

Functions in plugins can be registered as /bot commands by decorating them with @command.register(admin=False) decorator.

If admin parameter is False (default), anyone can run the command. If admin is True, only admins (as set in config.json) can run it.

See existing commands for examples.

hangupsbot's People

Contributors

wardellbagby avatar xmikos avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

hangupsbot's Issues

Question about conv_leave

At

Usage: /bot leave [conversation_name]"""

It is said that the usage is "/bot leave" whereas all other command, the in-chat-command is the same name as the python function. I don't see any redefinition for this particular case. Is that a mistake in code or am I missing something?

Thanks.

PS : Are issues a good way to ask this kind of question? Or is there a better way?

Set Admin

I'm trying to use some admin commands, but the bot doesn't seem to recognize me as admin, I've added both the conversation id and hangouts username of the person I want to set as admin, but I'm still getting the "I'm sorry Dave" error. What do I enter into config.json to set someone as admin?

how do i integrate hangupsbot with a bot made in "api.ai"?

I have made a bot in api.ai, but they don't provide integration with hangouts. hangupsbot seems to be the solution but I am not sure, is it possible?.
If its possible, how do I use hangups bot as a webservice to get and respond to the bot made in api.ai.

Inevitable crash

I seem to be experiencing an inevitable crash of hangupsbot. Not sure if you are still working on it, so no worries if not, but fwiw, the relevant traceback is below.

This has occurred each time I've tested it, a couple minutes into running and successful bot responses.

Exception ignored in: <bound method _UnixSelectorEventLoop.__del__ of <_UnixSelectorEventLoop running=False closed=True debug=False>>
Traceback (most recent call last):
  File "/usr/lib/python3.4/asyncio/base_events.py", line 361, in __del__
  File "/usr/lib/python3.4/asyncio/unix_events.py", line 57, in close
  File "/usr/lib/python3.4/asyncio/unix_events.py", line 138, in remove_signal_handler
TypeError: signal handler must be signal.SIG_IGN, signal.SIG_DFL, or a callable object

self._on_connect call is missing 'initial_data' parameter

Hangupsbot does not connect and gives error: "_on_connect() missing required positional argument 'initial_data'".

On line 179 the call is missing the 'initial_data' variable:
self._clienton_connect.add_observer(self._on_connect)

Best regards:
Mikael

Commands conv_create and conv_add don't work

Hi
How do i use the command "/bot conv_add" correctly ?
I always get the error:
Request failed with status 4: 'At least one invitee is required'
Following the instructions in the conversations.py
"Usage: /bot conv_add conversation_name [user_name_1] [user_name_2] [...]",
i tried:
-/bot conv_add . 123000000000000 (the gaia_id)
-/bot conv_add . [email protected]
-/bot conv_add . john.snow
and everything with "" and []:
-/bot conv_add . "123000000000000"
-/bot conv_add . [123000000000000]
...
What am i doing wrong?

Same at "/bot conv_create":
This command produces the error:
'ConversationList' object has no attribute 'add_conversation'
when i type:
/bot conv_create Test 12300000000000 124000000000000
or
/bot conv_create Test [email protected] [email protected]

Please help

Invalid syntax on line 115

pi@raspberrypi ~/hangupsbot $ python3 hangupsbot
Traceback (most recent call last):
File "/usr/lib/python3.2/runpy.py", line 143, in _run_module_as_main
mod_name, loader, code, fname = _get_main_module_details()
File "/usr/lib/python3.2/runpy.py", line 186, in _get_main_module_details
return _get_module_details(main_name)
File "/usr/lib/python3.2/runpy.py", line 115, in _get_module_details
code = loader.get_code(mod_name)
File "/usr/lib/python3.2/pkgutil.py", line 281, in get_code
self.code = compile(source, self.filename, 'exec')
File "/home/pi/hangupsbot/hangupsbot/main.py", line 115
res = yield from http_utils.fetch('get', link)
^
SyntaxError: invalid syntax

is there any way to fix this? I'm using python3.4.3.

Application fails to start

I've cloned the repo, ran setup.py install, and pip3 belives all the dependencies are satisfied. hangupsbot returns:

  Traceback (most recent call last):
File "/usr/bin/hangupsbot", line 4, in <module>
  hangupsbot.main()
File "/usr/lib/python3.4/site-packages/hangupsbot/hangupsbot.py", line 284, in main
  bot = HangupsBot(args.cookies, args.config)
File "/usr/lib/python3.4/site-packages/hangupsbot/hangupsbot.py", line 51, in __init__
  self.config = hangupsbot.config.Config(config_path)
File "/usr/lib/python3.4/site-packages/hangupsbot/config.py", line 11, in __init__
  self.load()
File "/usr/lib/python3.4/site-packages/hangupsbot/config.py", line 16, in load
  self.config = json.load(open(self.filename))
File "/usr/lib/python3.4/json/__init__.py", line 268, in load
  parse_constant=parse_constant, object_pairs_hook=object_pairs_hook, **kw)
File "/usr/lib/python3.4/json/__init__.py", line 318, in loads
  return _default_decoder.decode(s)
File "/usr/lib/python3.4/json/decoder.py", line 343, in decode
  obj, end = self.raw_decode(s, idx=_w(s, 0).end())
File "/usr/lib/python3.4/json/decoder.py", line 361, in raw_decode
  raise ValueError(errmsg("Expecting value", s, err.value)) from None
ValueError: Expecting value: line 5 column 3 (char 100)

Getting Started Guide?

I just got hangups and hangupsbot setup and running.

I am not quite sure how to configure hangupsbot to do autoreplies and handle commands.

{
  "admins": ["MY_USERNAME"],
  "autoreplies": [
    [["hi", "hello"], "Hello world!"],
    [["bot"], "At your service!"]
  ],
  "autoreplies_enabled": true,
  "commands_admin": ["quit", "config"],
  "commands_enabled": true,
  "commands_aliases": ["/bot", "/hal", "/cylon", "/skynet", "/terminator"],
  "forwarding_enabled": true,
  "conversations": {
    "UgwELlTjFXV9qwSBsB94AaABAQ": {
      "autoreplies_enabled": true,
      "commands_enabled": true
    }
  }
}

I have one conversation that I want to be active, but when I message in that chat, nothing seems to be happening.

Running hangupsbot on a virtual machine on cloud for 24*7

I am running hangupsbot on a google compute engine vm instance, but the problem is after a certain period of time(due to inactivity), it disconnects and stops responding to the messages.
How to make that bot always running on that vm?

Connected loop

After sucessfull token exchange, may the special chars in the hangouts:

Connected!
Conversations:
Client unexpectedly disconnected:
'ascii' codec can't encode character '\xfc' in position 18: ordinal not in range(128)
Waiting 5 seconds...
Trying to connect again (try 1 of 5)...
Connected!
Conversations:
Client unexpectedly disconnected:
'ascii' codec can't encode character '\xfc' in position 18: ordinal not in range(128)
Waiting 5 seconds...

asyncio.async invalid syntax error

After installing a fresh version of all dependencies and hangupsbot itself, this error is given when attempting to run hangupsbot.

Traceback (most recent call last):
File "/usr/local/bin/hangupsbot", line 11, in
load_entry_point('HangupsBot==1.7.1', 'console_scripts', 'hangupsbot')()
File "/usr/lib/python3/dist-packages/pkg_resources/init.py", line 490, in load_entry_point
return get_distribution(dist).load_entry_point(group, name)
File "/usr/lib/python3/dist-packages/pkg_resources/init.py", line 2854, in load_entry_point
return ep.load()
File "/usr/lib/python3/dist-packages/pkg_resources/init.py", line 2445, in load
return self.resolve()
File "/usr/lib/python3/dist-packages/pkg_resources/init.py", line 2451, in resolve
module = import(self.module_name, fromlist=['name'], level=0)
File "/usr/local/lib/python3.8/dist-packages/HangupsBot-1.7.1-py3.8.egg/hangupsbot/main.py", line 90
asyncio.async(
^
SyntaxError: invalid syntax

Using python 3.8.2, asyncio 0.4.1 ( also tried the most recent version 3.4.3) and appdirs 1.4.4

How to run the functionality provided by hangupsbot

hangupsbot is running in my system(linux ubuntu 14.04). But after hangupsbot is connected to my gmail account, it just shows my previous conversations.

How can i use the functionalities given(bot interaction) after this. When I write anything in the terminal, nothing happens.

githubpic

Wait for the user's response

Is there a way that within a command, the bot waits for an answer?

Example:

User command: get_forecast
Bot answer: Where?
User: "new york"

Everything within the same command

Fails to start: with "_on_connect() missing 1 required positional argument: 'initial_data"

Hangups is global and works correctly. I recently ran this bot on an older computer without problem, maybe issues with a newer version of hangups?

Client unexpectedly disconnected:
_on_connect() missing 1 required positional argument: 'initial_data'
Traceback (most recent call last):
File "/home/user/projects/hubot/node_modules/hubot-hangups/HangoutsBot/hangupsbot.py", line 137, in run
loop.run_until_complete(self._client.connect())
File "/usr/lib/python3.4/asyncio/base_events.py", line 208, in run_until_complete
return future.result()
File "/usr/lib/python3.4/asyncio/futures.py", line 243, in result
raise self._exception
File "/usr/lib/python3.4/asyncio/tasks.py", line 298, in _step
result = coro.throw(exc)
File "/usr/local/lib/python3.4/dist-packages/hangups/client.py", line 99, in connect
yield from self._listen_future
File "/usr/lib/python3.4/asyncio/futures.py", line 348, in iter
yield self # This tells Task to wait for completion.
File "/usr/lib/python3.4/asyncio/tasks.py", line 351, in _wakeup
value = future.result()
File "/usr/lib/python3.4/asyncio/futures.py", line 243, in result
raise self._exception
File "/usr/lib/python3.4/asyncio/tasks.py", line 300, in _step
result = coro.send(value)
File "/usr/local/lib/python3.4/dist-packages/hangups/channel.py", line 214, in listen
yield from self._longpoll_request()
File "/usr/local/lib/python3.4/dist-packages/hangups/channel.py", line 343, in _longpoll_request
yield from self._on_push_data(chunk)
File "/usr/local/lib/python3.4/dist-packages/hangups/channel.py", line 364, in _on_push_data
yield from self.on_connect.fire()
File "/usr/local/lib/python3.4/dist-packages/hangups/event.py", line 50, in fire
yield from gen
File "/usr/local/lib/python3.4/dist-packages/hangups/event.py", line 48, in fire
gen = observer(_args, *_kwargs)
TypeError: _on_connect() missing 1 required positional argument: 'initial_data'

How to retrieve email id of user who sent the message to bot

How to retrieve email id of user who sent the message to bot before it is added to conversation i.e. new users?
I have tried accessing all the possible methods, but unable to get the email id (first name and last name are there) of new users(who are not in the conversation list).

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.