3

I'm trying to run a rule in Outlook that runs a VBScript which calls a Slack.com webservice and updates one of my Slack Channels with a specific message. Current state -- i just want it to post a static message. Future state i'm going to try to use RegEx to parse out certain data from the email and post it to my slack channel.

From frankensteining a few scripts i found online, this is what i have (but doesn't quite work) Hoping someone can help...

    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
Birkley
  • 183
  • 1
  • 13
  • Also if you're unfamiliar with Slack, here is a sample curl request `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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 ` – Birkley Feb 20 '15 at 20:44

1 Answers1

5

So I resolved this myself, but wanted to post more details.

Request : I want to make a call to Slack and update one of my channels with a custom message WHEN I receive an email and an Outlook rule is triggered (message from X and sent to Y).

Solution : First off, you need to navigate to selfcert.exe in your Microsoft Office folders on the C drive, create a new self-signed certificate, and then add that certificate to Trusted Publishers in Outlook. AFTER that's done, I opened Visual Basic from Outlook by pressing Alt+F11 and created the following script in the "ThisOutlookSession" project.

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

Finally I created a rule that looked for the appropriate parameters and then peformed a "Run this script" action. When you click on the "script" name in the rule, a window will popup and you can select the above script you already created.

Hope this is helpful to someone!

Birkley
  • 183
  • 1
  • 13