基于各种触发器的机器人自动响应平台

gramhopper的Python项目详细描述


格拉姆霍珀

imageimageimage

基于各种触发器的自动响应的机器人平台。

安装

使用pip

安装最新版本:

$ pip install gramhopper

使用Docker

拉取最新图像:

$ docker pull orbin/gramhopper:latest

配置

创建机器人

  1. Create a bot using BotFather
  2. 将接收到的令牌保存在~/.gramphopper/token.txt
  3. 通过向botfather发送/setprivacy,启用从bot的组接收消息, 然后选择新的bot并单击Disable

为基于用户的规则启用昵称

要使用用户昵称,必须先获取用户ID。

在电报中获取用户ID

使用@userinfobot

  • 转到@userinfobot并按“开始”。 然后机器人将打印您的用户ID。
  • 要获取另一个用户的用户ID,只需转发来自该用户的消息,机器人就会打印其用户ID。

将昵称映射到用户ID

要使用用户昵称,~/.gramphopper/users.json应该包含一个对象,其中键 是昵称,值是用户ID,例如:

{"nickname1":123456789,"nickname2":987654321}

规则配置

配置文件位于~/.gramphopper/rules.yml

基本上,配置文件有三个部分:

  • global triggers:可以在规则中使用而无需重新定义的触发器。
  • global responses:可以在规则中使用而无需重新定义的响应。
  • 规则:触发器和响应对,它们共同定义了触发bot的内容和它的响应方式。

rules.yml示例

以下配置文件:

triggers:-name:cattype:text.has_exact_wordword:-Meow-meow-name:ducktype:text.has_exact_wordword:Quackresponses:-name:found_dogtype:preset.replypreset_response:-Hey, here's a dog!rules:# Identifies a cat (a global "cat" trigger) and sends "Hello cat!" (an inline response).-trigger:catresponse:type:preset.messagepreset_response:Hello cat!# Identifies a dog (an inline trigger) and replies "Hey, here's a dog!"# (a global "found_dog" response).-trigger:type:text.has_substringsubstring:-Woof-woof-Ruff-ruffresponse:found_dog# Identifies an animal sound (an inline trigger) and replies # 'I hear "(the animal sound)"' (an inline response), with a 30% probability.-trigger:type:text.regexppattern:^(Quack|Meow|Woof|Moo)$response:type:match.messagetemplate:I hear "{0}"probability:0.3# Identifies 5 occurrences in 60 seconds of a duck sound (an inline event_streak# trigger that uses a global "duck" trigger") and replies "Shut up duck!".-trigger:type:event_streakcounting_event_trigger:duckstreak_timeout_sec:60event_count:5response:type:preset.messagepreset_response:Shut up duck!

将产生以下对话:

运行

要运行gramhopper,只需运行:

来自已安装的软件包
$ gramhopper

来自Docker图像

$ docker run -it -v /your/configuration/dir:/root/.gramhopper orbin/gramhopper:latest

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
java为什么@DELETE REST不起作用?   带有JPA2的java表值参数。1和Hibernate,Sql Server   如何将Java类添加到Xamarin VS2017项目   绘制多边形时出现java空指针异常   java Apache WebClient 303状态未重定向   java如何用一组字符串数组从数据库中获取数据   java是否可以使用Google Drive API向文件中添加脚本?   java组织。阿帕奇。贾斯珀。JspC jar文件下载   java在整个JSON映射中将单个值作为JSON流   通过命令行将文件输入到java   java rs.next()总是返回false   java标记异常,通知调用方利用异常消息   java Spring YML数组属性为空