【问题标题】:Call Slack API via VBScript Rule in Outlook在 Outlook 中通过 VBScript 规则调用 Slack API
【发布时间】:2020-10-06 04:59:53
【问题描述】:

我正在尝试在 Outlook 中运行一个规则,该规则运行一个调用 Slack.com Web 服务并使用特定消息更新我的一个 Slack 频道的 VBScript。当前状态——我只想让它发布一条静态消息。未来我将尝试使用 RegEx 从电子邮件中解析出某些数据并将其发布到我的 slack 频道。

根据我在网上找到的一些脚本,这就是我所拥有的(但不太好用)希望有人能提供帮助......

    Function ProcessSend()
    Set oXMLHTTP = CreateObject("MSXML2.XMLHTTP.4.0")
    Set oXMLDoc = CreateObject("MSXML2.DOMDocument")

    strEnvelope = "payload={""channel"": ""#edt-error"", ""text"": ""This is posted to #edt-error.""}"

    Call oXMLHTTP.Open("POST", "https://custom-slack-url-for-service-goes-here.com" & posFirm, False)
    Call oXMLHTTP.setRequestHeader("Content-Type", "application/x-www-form-urlencoded")
    Call oXMLHTTP.Send(strEnvelope)

    Dim szResponse: szResponse = oXMLHTTP.responseText
    Call oXMLDoc.LoadXML(szResponse)

    If (oXMLDoc.parseError.ErrorCode <> 0) Then
        'call msgbox("ERROR")
        response = oXMLHTTP.responseText&" "&oXMLDoc.parseError.reason
        'call msgbox(oXMLDoc.parseError.reason)
    Else
        response = oXMLDoc.getElementsByTagName("string")(0).ChildNodes(0).Text
    End If
End Sub

【问题讨论】:

  • 另外,如果你不熟悉 Slack,这里是一个 curl 请求示例curl -X POST --data-urlencode 'payload={"channel": "#edt-error", "username": "webhookbot", "text": "This is posted to #edt-error and comes from a bot named webhookbot.", "icon_emoji": ":ghost:"}' https://hooks.slack.com/services/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

标签: regex vbscript outlook slack-api


【解决方案1】:

所以我自己解决了这个问题,但想发布更多细节。

请求:当我收到一封电子邮件并触发 Outlook 规则(来自 X 并发送到 Y 的消息)时,我想拨打 Slack 并使用自定义消息更新我的一个频道.

解决方案:首先,您需要导航到 C 盘上 Microsoft Office 文件夹中的 selfcert.exe,创建一个新的自签名证书,然后将该证书添加到 Trusted Publishers外表。完成后,我通过按 Alt+F11 从 Outlook 打开 Visual Basic,并在“ThisOutlookSession”项目中创建了以下脚本。

Sub ProcessSend(Item As Outlook.MailItem)
    Set oXMLHTTP = CreateObject("MSXML2.XMLHTTP.6.0")
    Set oXMLDoc = CreateObject("MSXML2.DOMDocument")

    strEnvelope = "payload={""channel"": ""#edt-error"", ""text"": ""This is posted to #edt-error.""}"

    Call oXMLHTTP.Open("POST", "https://INSERT-YOUR-SERVICE-URL-HERE" & posFirm, False)
    Call oXMLHTTP.setRequestHeader("Content-Type", "application/x-www-form-urlencoded")
    Call oXMLHTTP.Send(strEnvelope)

    Dim szResponse: szResponse = oXMLHTTP.responseText
    Call oXMLDoc.LoadXML(szResponse)
End Sub

最后,我创建了一个规则来查找适当的参数,然后执行“运行此脚本”操作。当您点击规则中的“脚本”名称时,会弹出一个窗口,您可以选择上面已经创建的脚本。

希望这对某人有帮助!

【讨论】:

    猜你喜欢
    • 2017-08-29
    • 2016-12-27
    • 2023-03-06
    • 1970-01-01
    • 1970-01-01
    • 2015-11-13
    • 2014-02-06
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多