本文介绍了Slack API - 如何在从 slack 发送数据时删除消息格式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在构建一个 Slack 机器人.你向我的机器人提供了一些信息,包括一个电子邮件地址,它通过一个传出的 webhook 发送数据.

I'm building a slack bot. You feed my bot several info, including an email address, and it sends the data through an outgoing webhook.

问题是,如果我给我的机器人所需的信息,http 请求会返回这个(示例):

The problem is that if I give my bot the required info, the http request returns this (exemple) :

{"name":"Alexandre","email":"<mailto:test@gmail.com|test@gmail.com>","test":"hello world"}

这很糟糕,因为捕获钩子的服务器 (zapier) 无法解释带有括号的 mailto:.此消息格式是 slack 自动执行的操作.关于如何删除 URL 和电子邮件的消息格式的任何想法?

This sucks, because the server catching the hook (zapier) cannot interpret the mailto: with the brackets. This message formatting is something slack does automatically. Any ideas on how I can remove message formatting for URLs and emails ?

谢谢!

推荐答案

我不知道你是否解决了这个问题.我刚刚遇到了同样的问题.我使用 Python 构建了我的 slackbot,并创建了一种方法来摆脱mailto".这可能不是您正在寻找的答案,但希望它能提供一些见解:

I don't know if you've fixed this issue. I just encountered the same problem. I built my slackbot using Python and I created a method to get rid of the "mailto". This might not be the answer that you are looking for, but hopefully it gives some insight:

def unformat_message(param):
    while param.count('mailto') >= 1:
        mailto_position_at_param = param.find("<mailto")
        end_of_mailto_position_at_param = param.find("com>")
        taken_email_position = param.find("com|")
        if mailto_position_at_param != -1 and end_of_mailto_position_at_param != -1 and taken_email_position != -1:
          old_string = param[mailto_index:end_mailto_index+4]
          new_string = param[mailto_index+8:email_index+3]
          param = param.replace(old_string,new_string)
    return param

这篇关于Slack API - 如何在从 slack 发送数据时删除消息格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-07 00:29