这是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许可获得许可。