これは、errbot(https://errbot.io)のGoogleハングアウトチャット(https://chat.google.com)のバックエンドです。
ERRBOTを使用してボットを作成することができますが、いつものように、それは進行中の作業です。
git clone https://github.com/cloudflare/GHC-Errbot
その後
BACKEND = 'Google-Hangouts-Chat'
BOT_EXTRA_BACKEND_DIR = '/path/to/where/you/cloned/the/repo/'
config.pyに
GCEプロジェクトでGoogle Pub/サブトピックを作成します
そのトピックに関するサブスクライバーを作成し、ボットアカウントのサブスクライバー許可を付与します
ボットにcreds.jsonを生成します
errbot init
を使用してアプリケーションを作成し、次の情報を使用してconfig.pyにBOT_IDENTITY
ブロックを作成します。
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>',
}
bot_prefixをボットの@
に設定します。
(オプション)プロメテウスメトリックを有効にするには、metrics_portを整数に設定します。これは、メトリックのために開くポートになります。
このバックエンドは、メッセージイベントの添付ファイルをサポートします。 Google Chatのアップロード添付ファイルをダウンロードするには、 Bearer認証を使用してGetAttachment APIとHTTP Get Requestを使用する必要があります。バックエンドは既に認証されているため、誤って使用できるダウンロードオブジェクトをメッセージコンテキストで提供するため、errbotプラグインが添付ファイルを直接ダウンロードできるように、追加の手順は必要ありません。
これは、ERRBOTプラグインでダウンローダーヘルパーを使用する方法のコード例です。
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'])
markdownconverter.py
のコードは、https://github.com/dr-beat/errbot-backend-hangoutschatからです。 MITライセンスです。
BSD 3ライセンスに基づいてライセンスされています。