hubot + rocket 配置文档

本文详细介绍如何安装和配置Hubot机器人与Rocket.Chat聊天平台,包括Node.js、npm的安装,以及通过Docker运行Hubot-Rocket.Chat适配器。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

1、安装hubot

1.1 安装node.js 和 npm

yum install -y nodejs npm
npm install -g inherits n
yum install -y curl

1.2 安装yo generator-hubot

npm install -g yo generator-hubot
npm install coffee-script -save

以下包可选:
npm install hubot-test-helper --save-dev
npm install expect.js
npm install chai

1.3 创建一个目录,并实例化一个hubot

mkdir myhubot
cd myhubot
yo hubot 

这里写图片描述

1.4 启动hubot

./bin/hubot -a rocketchat

2、安装rocketchat

2.1 安装mongodb

vim /etc/yum.repos.d/mongodb-org.repo
[mongodb-org-3.4]
name=MongoDB Repository
baseurl=https://repo.mongodb.org/yum/redhat/$releasever/mongodb-org/3.4/x86_64/
gpgcheck=1
enabled=1
gpgkey=https://www.mongodb.org/static/pgp/server-3.4.asc
yum -y install mongodb-org
systemctl start mongod
systemctl enable mongod

2.2 安装rocketchat

cd /opt
curl -L https://rocket.chat/releases/latest/download -o rocket.chat.tgz tar zxvf rocket.chat.tgz mv bundle Rocket.Chat 
cd Rocket.Chat/programs/server
npm install

这里写图片描述

2.3 启动rocketchat

cd /opt/Rocket.Chat
export ROOT_URL=http://xxx.rocket.com/
export MONGO_URL=mongodb://localhost:27017/rocketchat
export PORT=3000 
node main.js

2.4 nginx配置

upstream rocketchat_backend {
  server 127.0.0.1:3000;
}

server {
        listen 80;
        server_name youdao.rocket.com;
        charset utf-8;

        root /opt/www/xxx.rocket.com;
        index index.html index.htm;

        access_log  /var/log/nginx/rocket.com_access.log;
        error_log   /var/log/nginx/rocket.com_error.log;
       }

    location / {
        proxy_pass http://rocketchat_backend/;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "upgrade";
        proxy_set_header Host $http_host;

        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forward-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forward-Proto http;
        proxy_set_header X-Nginx-Proxy true;

        proxy_redirect off;
    }
}

2.5 浏览器输入xxx:3000

这里写图片描述

3、安装hubot-rocketchat adapter

3.1 启动一个docket镜像

docker run -it -e ROCKETCHAT_URL="http://IP:3000" \
-e ROCKETCHAT_ROOM='' \
-e LISTEN_ON_ALL_PUBLIC=true \
-e ROCKETCHAT_USER=admin \
-e ROCKETCHAT_PASSWORD=123456 \
-e ROCKETCHAT_AUTH=password \
-e BOT_NAME=bot \
-e EXTERNAL_SCRIPTS=hubot-pugme,hubot-help \
rocketchat/hubot-rocketchat

3.2 启动时,指定环境变量,使得Hubot等登录上rocketchat(注意:在启动hubot之前,先刷环境变量)

export ROCKETCHAT_URL="http://IP:3000" 
export ROCKETCHAT_ROOM='' 
export LISTEN_ON_ALL_PUBLIC=true
export ROCKETCHAT_USER=admin 
export ROCKETCHAT_PASSWORD=123456 
export ROCKETCHAT_AUTH=password

3.3 验证

编辑myhubot/scripts目录下的example.coffee文件,添加如下行:

robot.hear /hi/i, (res) ->
     res.reply "hello"
robot.hear /吃饭了吗/, (res) ->
     res.send '只有你们这些愚蠢的人类才吃饭'

在rocketcha里面对话如下,测试ok
这里写图片描述

3.4 hubot 运行bash脚本,安装插件:hubot-script-shellcmd

cd myhubot
npm install hubot-script-shellcmd
cp -R node_modules/hubot-script-shellcmd/bash .   #seperate your shellcmd from the npm module

编辑 external-scripts.json
add 'hubot-script-shellcmd' 

上述操作完成后,我们可以看到,在myhubot目录下有个bash目录,cd bash/handlers,该目录下有两个文件:helloworld,update,在rocketchat中,可以直接执行@admin shellcmd 以及@admin shellcmd helloworld执行上面的命令.
这里写图片描述

4 、参考文献

要计算在一个给定迷宫中走出所需的最短步数,通常可以使用广度优先搜索(Breadth-First Search, BFS)算法。BFS适合寻找最短路径的问题,因为它总是先访问最近的节点。以下是使用C++实现的一个简单BFS解迷宫问题的步骤: 1. 定义一个二维数组表示迷宫,其中0代表空地,1代表墙壁,S代表起点,E代表终点。 2. 创建一个队列用于存储待探索的节点及其步数。 3. 初始化步数,起点的步数为0,并将它放入队列。 4. 当队列不为空时,循环处理: a. 弹出队首节点,检查是否到达终点。如果是,则返回当前步数。 b. 否则,遍历该节点的所有相邻节点(上下左右),如果邻居是空地并且未被访问过,更新其步数为当前节点步数加一,并加入队列。 5. 如果没有找到出口,说明迷宫无解。 下面是一个简单的C++代码示例: ```cpp #include <iostream> #include <vector> #include <queue> using namespace std; int bfs(vector<vector<int>>& maze, int startRow, int startCol) { vector<vector<bool>> visited(maze.size(), vector<bool>(maze[0].size(), false)); queue<pair<int, int>> q; // 存储节点和步数 q.push({startRow, startCol}); visited[startRow][startCol] = true; while (!q.empty()) { pair<int, int> node = q.front(); q.pop(); if (node.first == maze.size() - 1 && node.second == maze[node.first].size() - 1) { // 到达终点 return node.first + node.second; // 返回步数 } for (auto& neighbor : {{-1, 0}, {1, 0}, {0, -1}, {0, 1}}) { // 上下左右 int newRow = node.first + neighbor.first; int newCol = node.second + neighbor.second; if (newRow >= 0 && newRow < maze.size() && newCol >= 0 && newCol < maze[newRow].size() && !visited[newRow][newCol] && maze[newRow][newCol] == 0) { visited[newRow][newCol] = true; q.push({newRow, newCol}); } } } return -1; // 无解 } int main() { vector<vector<int>> maze = {{1, 0, 0, 1}, {1, 0, 0, 1}, {0, 0, 0, 0}, {0, 0, 1, 1}}; int startRow = 0, startCol = 0; // 起点位置 int endRow = maze.size() - 1, endCol = maze[endRow].size() - 1; // 终点位置 int shortestSteps = bfs(maze, startRow, startCol); cout << "Shortest steps to exit the maze: " << shortestSteps << endl; return 0; } ```
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值