GithubHelp home page GithubHelp logo

isabella232 / ghc-errbot Goto Github PK

View Code? Open in Web Editor NEW

This project forked from cloudflare/ghc-errbot

0.0 0.0 0.0 85 KB

A Google Hangouts Chat Backend for Errbot

License: BSD 3-Clause "New" or "Revised" License

Python 100.00%

ghc-errbot's Introduction

Google Hangouts Chat - Errbot Backend

This is a backend for Google Hangouts Chat (https://chat.google.com) for Errbot(https://errbot.io).

It allows you to use errbot to create bots, but as always, it's a work in progress.

Installation

git clone https://github.com/cloudflare/GHC-Errbot

and then

BACKEND = 'Google-Hangouts-Chat'
BOT_EXTRA_BACKEND_DIR = '/path/to/where/you/cloned/the/repo/'

to your config.py

Authentication

  1. Create a Google Pub/Sub topic in a GCE project

  2. Create a Subscriber on that topic and grant your bot account Subscriber permissions

  3. Generate a creds.json for your bot

  4. Create an application with errbot init, and then create a BOT_IDENTITY block in your config.py with the following information:

BOT_IDENTITY = {
    'GOOGLE_CREDS_FILE': '/path/to/bot/creds.json',
    'GOOGLE_CLOUD_ENGINE_PROJECT': '<your project name>',
    'GOOGLE_CLOUD_ENGINE_PUBSUB_TOPIC': '<your pub/sub topic>',
    'GOOGLE_CLOUD_ENGINE_PUBSUB_SUBSCRIPTION': '<your pub/sub subscription name>',
}
  1. Set BOT_PREFIX to the name of the bot, including the mention(@)

Examples

Attachments

This backend supports attachments in message events. To download a Google Chat upload attachment, we need to use the GetAttachment API and HTTP GET request with Bearer authentication. Since the backend is already authenticated, we opportunistically provide a ready-to-use downloader object with the message context, so that errbot plugins can use it to directly download the attachments, no extra steps required.

Here's a code example on how to use the downloader helper in a errbot plugin:

from io import BytesIO
from errbot import BotPlugin, botcmd

@botcmd(split_args_with=None)
def upload(self, msg, args):
    attachments = msg._extras.get('attachment', [])
    for attachment in attachments:
        if attachment['source'] == 'UPLOADED_CONTENT':
            url = f"""https://chat.googleapis.com/v1/media/{ attachment['attachmentDataRef']['resourceName'] }?alt=media"""
            downloader = msg._extras.get('downloader')
            content = downloader(url)
            if content != None:
                d = BytesIO()
                d.write(content)
                # jira.add_attachment(issue=issue, attachment=d, filename=attachment['contentName'])

Acknowledgement

The code in markdownconverter.py is from https://github.com/dr-BEat/errbot-backend-hangoutschat. It is MIT licensed.

License

Licensed under the BSD 3 License.

ghc-errbot's People

Contributors

celso avatar iseyer avatar jbampton avatar kimnorgaard avatar larcher avatar nickzylstra avatar sinkingpoint avatar worenga avatar

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.