处理松弛消息中提到的一些函数
slackmentions的Python项目详细描述
懒散提及
提供处理松弛消息中提及的函数。
用法
可用功能:
- 查找人:
查找松弛文本中提到的用户名并创建SlackPerson对象 为了那些人。返回那些slackperson对象的列表。 这可以用于获取有关用户的更多信息,或者如果相同的文本 将被多次处理。
参数:
文本:查找@引用的文本。
userlist:slack api users.list的输出
静默:如果发现有人提到slackperson.slackdataerror 在文本中,但不在用户列表中。如果设置为真的话 错误地忽略了这一点。
返回:slackperson对象列表或空列表。
- 提及文本:
将文本中提到的用户名替换为用于标记的用户ID 松弛API消息发送。
参数:
文本:包含@提到的文本
人物:文本中找到的人物的SlackPerson对象列表。如果没有 指定时,将通过将文本和用户列表传递给 找到人。如果未提供用户列表,则为必需。
userlist:slack api users.list中的json。如果没有人需要 提供。
静默:如果发现有人提到slackperson.slackdataerror 在文本中,但不在用户列表中。如果设置为真的话 错误地忽略了这一点。仅适用于指定了userlist的情况,而不是 人。
- 清除文本:
从文本中删除@references 参数:
文本:包含@提到的文本
人物:文本中找到的人物的SlackPerson对象列表。如果没有 指定时,将通过将文本和用户列表传递给 找到人。如果未提供用户列表,则为必需。
userlist:slack api users.list中的json。如果没有人需要 提供。
静默:如果发现有人提到slackperson.slackdataerror 在文本中,但不在用户列表中。如果设置为真的话 错误地忽略了这一点。仅适用于指定了userlist的情况,而不是 人。
全部清除:设置为true忽略用户列表和用户,只使用核弹 所有提及内容
import slackmentions from slackclient import SlackClient sc = SlackClient(os.environ['SLACK_API_TOKEN']) userlist = sc.api_call('users.list') text = 'hi @joe, could you tell @kathy to call me?' people = slackmentions.findpeople(text, userlist) # people = [SlackPerson(userid='U0000001', username='joe'), SlackPerson(userid='U0000002', username='kathy')] withmentions = slackmentions.mention_text(text, people=people) # withmentions = 'hi <@U0000001>, could you please tell <@U0000002> to call me?' withmentions2 = slackmentions.mention_text(text, userlist=userlist) assert withmentions = withmentions2 cleantext = slackmentions.clean_text(text, people=people) # cleantext = 'hi, could you please tell to call me?'
测试
每种方法都有测试,测试成功,出现错误,错误 吞入,缺少关键字参数。它们可以使用pytest运行。