OneBot application launcher implemented using ts, supports icqq, qq official robot, WeChat and DingTalk robot
Docs
Usage example
Global installation (not recommended after 0.4.8)
1 Install dependencies
2 Initialize configuration file
Execute the following command in the directory where you want to store the configuration file
3. Change the generated default configuration file to the configuration you want and run the above command again to start the project.
partial installation
1 Initialize the node project
2. Install onebots and corresponding adapter dependencies
npm install onebots
npm install @icqqjs/icqq # 如需使用icqq适配器,请务必安装
npm install web-wechat # 如需使用微信适配器,请务必安装
npm install qq-official-bot # 如需使用qq官方机器人适配器,请务必安装
npm install node-dd-bot # 如需使用钉钉机器人适配器,请务必安装
- Regarding the installation guide of @icqqjs:
Install:
- Create a new file
.npmrc
in your project root directory and enter the following content
@icqqjs:registry=https://npm.pkg.github.com
- Enter
npm login --scope=@icqqjs --auth-type=legacy --registry=https://npm.pkg.github.com
on the command line, press Enter, and log in to github according to the prompts
npm login --scope=@icqqjs --auth-type=legacy --registry=https://npm.pkg.github.com
UserName: # 你的github账号
Password: # 前往 https://github.com/settings/tokens/new 获取,scopes勾选 read:packages
E-Mail: # 你的公开邮箱地址
- Install dependencies
npm install @icqqjs/icqq # or > yarn add @icqqjs/icqq
3. Execute the following command to generate the configuration file
npx onebots -r icqq #注册icqq适配器并启动onebots
npx onebots -r wechat #注册微信适配器并启动onebots
npx onebots -r qq #注册qq官方适配器并启动onebots
npx onebots -r dingtalk #注册钉钉适配器并启动onebots
# 你也可以同时注册多个适配器,多次使用-r即可,例如 npx onebots -r qq -r icqq -r wechat
4. Change the generated default configuration file to the configuration you want and run the above command again to start the project.
Default profile
port : 6727 # 监听端口
log_level : info # 日志等级
platform : 5 # 机器人客户端协议(1:Android 2:APad 3:Watch 4:IMac 5:IPad)
timeout : 30 #登录超时时间(秒)
general : # 通用配置,在单个配置省略时的默认值
V11 : # oneBotV11的通用配置
heartbeat : 3 # 心跳间隔 (秒)
access_token : " " # 访问api的token
post_timeout : 15 # 上报超时时间,(秒)
secret : " " # 上报数据的sha1签名密钥
rate_limit_interval : 4 # ws心跳间隔(秒)
post_message_format : string # "string"或"array"
reconnect_interval : 3 # 重连间隔 (秒)
use_http : true # 是否使用 http
enable_cors : true # 是否允许跨域
filters : {} # 过滤器配置
use_ws : true # 是否使用websocket
http_reverse : [] # http上报地址
ws_reverse : [] # 反向ws连接地址
V12 : # oneBotV12的通用配置
heartbeat : 3 # 心跳间隔 (秒)
access_token : " " # 访问api的token
request_timeout : 15 # 上报超时时间 (秒)
reconnect_interval : 3 # 重连间隔 (秒)
enable_cors : true # 是否允许跨域
use_http : true # 是否启用http
use_ws : true # 是否启用 websocket
filters : {} # 过滤器配置
webhook : [] # http 上报地址
ws_reverse : [] # 反向ws连接地址
protocol :
platform : 2
sign_api_addr : " " #你的签名地址
password : " " # 账号密码,未配置则扫码登陆
# ...其他配置项参考icqq的Config配置
# 每个账号的单独配置(用于覆盖通用配置)
icqq.123456789 :
password : " " # 账号密码,未配置则扫码登陆
version : V11 # 使用的oneBot版本
# ...其他配置项参见上方对应oneBot版本的通用配置
protocol :
platform : 2
sign_api_addr : " " #你的签名地址
# ...其他配置项参考icqq的Config配置
qq.123456789 : # `${适配器名称}:${appId}`
versions :
- version : V11
# 。。。其他配置项参见上方对应oneBot版本的通用配置
protocol : # 将会覆盖通用配置中的protocol
token : ' ' # qq机器人token
secret : ' ' # qq机器人secret
sandbox : false # 是否沙箱环境
intents : # 需要监听的intents
- ' GROUP_AT_MESSAGE_CREATE ' # 群聊@事件 没有群聊权限请注释
- ' C2C_MESSAGE_CREATE ' # 私聊事件 没有私聊权限请注释
- ' DIRECT_MESSAGE ' # 频道私信事件
# - 'GUILD_MESSAGES' # 私域机器人频道消息事件,公域机器人请注释
- ' GUILDS ' # 频道变更事件
- ' GUILD_MEMBERS ' # 频道成员变更事件
- ' GUILD_MESSAGE_REACTIONS ' # 频道消息表态事件
- ' INTERACTION ' # 互动事件
- ' PUBLIC_GUILD_MESSAGES ' # 公域机器人频道消息事件,私域机器人请注释
# 。。。其他配置项参见上方对应oneBot版本的通用配置
dingtalk.abcedfg : # `${适配器名称}:${clientId}`
versions :
- version : V11
- version : V12
protocol :
clientSecret : ' ' # 钉钉机器人秘钥 必填
username : '钉钉机器人' #钉钉后台配置的机器人名称 不填则显示'钉钉机器人'
avatar : ' ' # 机器人头像 不填则显示钉钉logo
wechat.bot1 : # `${适配器名称}:${机器人唯一标识}`
versions :
- version : V11
- version : V12
protocol : {}
Configuration explanation
Config
Configuration items | type | default value | desc |
---|
port | number | 6727 | Service listening port |
logLevel | string | info | Log level |
general | {V11:V11.Config,V12:V12.Config} | general | Common configuration |
[adapter].[number] | OneBotConfig | - | Robot configuration |
OneBotConfig
Configuration items | type | default value | desc |
---|
password | string | - | Only effective for icqq, if the account and password are not filled in or filled in blank, scan the QR code to log in. |
V11 | V11.Config | configV11 | V11 configuration |
V12 | V12.Config | configV12 | V12 configuration |
protocol | Configuration passed to client initialization | {} | |
ConfigV11
Configuration items | type | default value | desc |
---|
heartbeat | number | 3 | Heartbeat interval unit: seconds |
access_token | string | - | access token |
secret | string | - | Signing key |
rate_limit_interval | number | 4 | Speed limit interval unit: seconds |
post_message_format | string | string | Message formatting |
reconnect_interval | number | 3 | Reconnection interval unit: seconds |
use_http | boolean | false | Whether to use http protocol |
enable_cors | boolean | false | Whether to allow cross-domain |
filters | Filters | {} | Event filter configuration |
use_ws | boolean | false | Whether to use ws protocol |
http_reverse_url | string[] | - | http reporting address |
ws_reverse_url | string[] | - | Reverse ws connection address |
ConfigV12
Configuration items | type | default value | desc |
---|
heartbeat | number | 3 | Heartbeat interval unit: seconds |
access_token | string | - | access token |
request_timeout | number | 15 | Request timeout unit: seconds |
reconnect_interval | number | 3 | Reconnection interval unit: seconds |
enable_cors | boolean | false | Whether to allow cross-domain |
filters | Filters | {} | Event filter configuration |
use_http | boolean | false | Whether to use http protocol |
use_ws | boolean | false | Whether to use ws protocol |
webhook_reverse_url | string[] | - | webhook reporting address |
ws_reverse_url | string[] | - | Reverse ws connection address |
event filter
Grammar instructions
- The outermost layer of
onebots
' event filter is a JSON object, in which the key is the key. If it is an algorithm, the value is used as the parameter of the operator. If it is not an operator, it means filtering the corresponding key
of the event data object. - Any object in the filtering rule will only let the event pass if all its items match (equivalent to an and operation). If the value is an array, it means that
key
value corresponding to the event must satisfy one of them. - Available logical operators are:
$and
(logical AND), $or
(logical OR), $not
(logical NOT), $nor
(logical exclusive OR), $regexp
(text regular matching), $like
(text fuzzy matching) , $gt
(numeric greater than comparison), $gte
(numeric greater than or equal to comparison), $lt
(numeric less than comparison), $lte
(numeric less than or equal to comparison), $between
(numeric range comparison)
Example
1. Only report private chat events
filters :
message_type : private
2. Private chat or designated group chat
filters :
$or :
message_type : private
group_id :
- 123456789 987654321
3. Private chat event and not the designated user
filters :
message_type : private
$not :
user_id :
- 123456789 987654321
4. Private chat events (excluding events of specified users) or specified group chat events
filters :
$or :
- message_type : private
$not :
user_id : 123456789
- message_type : group
group_id : 987654321
5. Only report message events and the user is older than 18 years old
filters :
type : message
sender :
age :
$gt : 18
6. Only report message events and the message content is! message at the beginning
filters :
type : message
raw_message :
.regexp : ' ^!|! '
7. Do not report messages containing cnm
.
filters :
$not :
type : message
raw_message :
$like : cnm
Manage oneBot using API
url | method | params | desc |
---|
/list | GET | | Get the list of currently running robots |
/detail | GET | uin | Get the specified robot configuration |
/qrcode | GET | uin | Obtain the designated robot login QR code |
/add | POST | {uin,...config} | Add robot config for robot configuration |
/edit | POST | {uin,...config} | Modify the robot configuration config for the robot configuration |
/remove | get | uin, force | Remove the robot. When force is true, the robot data directory will be deleted. |
Acknowledgments
- icqqjs/icqq underlying service support
- takayama-lily/onebot oneBot V11 original version