這是Google Hangouts Chat(https://chat.google.com)的後端(https://errbot.io)。
它允許您使用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/sub主題
在該主題上創建訂戶並授予您的Bot帳戶訂戶權限
為您的機器人產生積分。
使用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設置為bot的名稱,包括提及( @
)
(可選)啟用Prometheus指標,將Metrics_port設置為整數。這將是您要為指標打開的端口。
此後端支持消息事件中的附件。要下載Google聊天上傳附件,我們需要使用Bearer Authentication使用GetAttachment API和HTTP GET請求。由於後端已經經過身份驗證,因此我們在機會上提供了一個帶有消息上下文的現成下載器對象,因此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許可獲得許可。