hubot README

The project's README from github.com/hubotio/hubot. As one markdown file: README.md.

Pipeline Status

Build Status: MacOS Build Status: Ubuntu Build Status: Window

Hubot

Note: v10.0.4 accidentally contains the removal of CoffeeScript; v10.0.5 puts it back in Note: v11 removes CoffeeScript and converts this codebase to ESM

Hubot is a framework to build chat bots, modeled after GitHub's Campfire bot of the same name, hubot. He's pretty cool. He's extendable with scripts and can work on many different chat services.

This repository provides a library that's distributed by npm that you use for building your own bots. See the documentation for details on getting up and running with your very own robot friend.

In most cases, you'll probably never have to hack on this repo directly if you are building your own bot. But if you do, check out CONTRIBUTING.md

Create your own Hubot instance

This will create a directory called myhubot in the current working directory.

npx hubot --create myhubot --adapter @hubot-friends/hubot-slack
npx hubot --create myhubot --adapter @hubot-friends/hubot-discord
npx hubot --create myhubot --adapter @hubot-friends/hubot-ms-teams
npx hubot --create myhubot --adapter @hubot-friends/hubot-irc

Review scripts/example.mjs. Create more scripts in the scripts folder.

Command bus (robot.commands)

Hubot includes a deterministic command subsystem for slash-style commands. It is safe by default and does not interfere with legacy hear and respond listeners.

Basic Command Registration

export default (robot) => {
	robot.commands.register({
		id: 'tickets.create',
		description: 'Create a ticket',
		aliases: ['ticket new', 'new ticket'],
		args: {
			title: { type: 'string', required: true },
			priority: { type: 'enum', values: ['low', 'medium', 'high'], default: 'medium' }
		},
		sideEffects: ['creates external ticket'],
		handler: async (ctx) => {
			return `Created ticket: ${ctx.args.title}`
		}
	})
}

Invoke with addressing the bot:

Commands that declare side effects will require confirmation before execution.

The user is asked to confirm. They do so like so:

@hubot yes
@hubot no
@hubot cancel

Aliases are for discovery and search only. They do not execute commands or create proposals. They are intent utterances.

Built-in Help Command

Hubot automatically registers a help command that provides command discovery and documentation:

@hubot help                          # List all commands
@hubot help tickets                  # Filter commands by prefix
@hubot help search "create ticket"   # Search by keyword, alias, description, or example

Search for Commands

const results = robot.commands.search('ticket new')
// [{ id: 'tickets.create', score: 100, matchedOn: 'alias' }, ...]

Custom Type Resolvers

Extend validation with custom argument types:

export default (robot) => {
	// Register custom type resolver
	robot.commands.registerTypeResolver('project_id', async (value, schema, context) => {
		if (!value.startsWith('PRJ-')) {
			throw new Error('must start with PRJ-')
		}
		return value.toUpperCase()
	})

	// Use it in a command
	robot.commands.register({
		id: 'projects.deploy',
		description: 'Deploy a project',
		args: {
			projectId: { type: 'project_id', required: true }
		},
		handler: async (ctx) => {
			return `Deploying ${ctx.args.projectId}`
		}
	})
}

Configuration Options

When creating a CommandBus instance, you can configure:

Permissions

Control who can execute commands using room-based and role-based permissions.

Room-Based Permissions

Restrict command execution to specific chat rooms:

robot.commands.register({
	id: 'sensitive.action',
	description: 'Admin-only action',
	permissions: {
		rooms: ['#admin', '#ops']  // Only allowed in these rooms
	},
	handler: async (ctx) => {
		return 'Action executed!'
	}
})

Users in other rooms get: Permission denied: command not allowed in this room

Role-Based Permissions

Restrict command execution to users with specific roles:

robot.commands.register({
	id: 'deploy.production',
	description: 'Deploy to production',
	permissions: {
		roles: ['admin', 'devops']  // Only users with these roles
	},
	handler: async (ctx) => {
		return 'Deploying...'
	}
})

To enable role checking, provide a permissionProvider when creating CommandBus:

const commandBus = new CommandBus(robot, {
	permissionProvider: {
		hasRole: async (user, requiredRoles, context) => {
			// Custom logic to check if user has any of the required roles
			const userRoles = await fetchUserRoles(user.id)
			return requiredRoles.some(role => userRoles.includes(role))
		}
	}
})

Without a permission provider, role-based permissions are ignored (allow by default). Room-based permissions are always enforced.

License

See the LICENSE file for license rights and limitations (MIT).

Hubot History

Say hello to Hubot

Cartoon with Hubot

The Most Important Startup's Hardest Worker Isn't a Person

The Story of Hubot

Hubot by Hubotics

Automating Inefficiencies

Getting Started with Hubot

hubot (hubotio/hubot)

Searching Database…

16.8K ·GitHub
这是什么?Hubot 是一个用于构建聊天机器人的框架,名字和设计都模仿了 GitHub 内部同名的 Campfire 聊天机器人。它以 npm 库的形式发布,你可以用它构建自己的机器人,并让机器人运行在多种聊天服务上。
这是现成的机器人,还是需要我在其基础上开发的框架?它是一个库/框架,不是成品机器人。你可以基于它生成自己的 Hubot 实例,然后通过自己的脚本和聊天适配器进行扩展。
我该如何用它创建自己的机器人?运行生成器来搭建新实例(例如 `bin/hubot --create myhubot`),这会创建一个 'myhubot' 目录,然后参照提供的示例,将你自己的脚本添加到 scripts 文件夹中。
运行 Hubot 机器人之前需要安装什么?你需要 Node.js 18 或更高版本,以及 npm 9 或更高版本;核心库本身依赖 express、express-basic-auth 和 pino 等包。
在版本之间升级是否安全,尤其是涉及 CoffeeScript 的时候?升级时请注意版本:v10.0.4 不慎移除了 CoffeeScript 支持,v10.0.5 又将其恢复;而 v11 则彻底移除了 CoffeeScript,并将代码库转换为 ESM,因此旧的 CoffeeScript 脚本在升级后可能会失效。
命令总线(robot.commands)功能是什么?它是一个用于斜杠式命令的确定性子系统,调用方式如 '@hubot tickets.create --title "VPN down"'。它可以与旧版 hear/respond 监听器安全地同时运行,并且可以要求用户对有副作用的命令进行确认。
可以限制谁能使用某些命令吗?可以。命令总线支持基于房间的权限(将命令限制在特定聊天房间内),以及通过自定义 permissionProvider 实现的基于角色的权限;基于房间的检查始终生效,而基于角色的检查仅在你提供了 provider 时才会执行。
Hubot 为什么会被创建?它最初在 GitHub 内部诞生,被称为'最重要的初创公司里最能干的员工'。它是一个用于自动化部署等各类低效工作的内部 Campfire 聊天机器人,后来被开源为本框架。
它是否内置帮助系统?是的,Hubot 会自动注册一个帮助命令,为所有已注册的命令提供查找和文档说明,包括仅用于搜索的别名。
Creator
hubotio
Size
4.5 MB
Stars
16.8K
Age
15y
Commits · 90 Days