Integrate Equipment to Slack

Super interesting, docker feels underutilized

Adding to the list of “integratable” equipment, here’s Biomek i7 for sending slack messages:

if Not World.Globals.Browserman.Simulating then
  Dim objHTTP, WebHookUrl, Payload
Set objHTTP = CreateObject("MSXML2.XMLHTTP")

' Your Webhook URL obtained from Slack
WebHookUrl = "YOUR_WEBHOOK_URL_HERE"

' Message to be sent to Slack
Payload = "{""text"": ""Hello world!""}"

objHTTP.Open "POST", WebHookUrl, False
objHTTP.setRequestHeader "Content-Type", "application/json"
objHTTP.send Payload
end if
ChatGPT can modify these pretty effectively. Here's a quick method start update

image

If Not World.Globals.Browserman.Simulating Then
    Dim objHTTP, WebHookUrl, Payload, currentTime, methodName, methodETA, estimatedEndTime
    Set objHTTP = CreateObject("MSXML2.XMLHTTP")

    ' Your Webhook URL obtained from Slack
    WebHookUrl = "ENTER YOUR WEBHOOK HERE"

    ' Get the current time
    currentTime = Now()

    ' Get the string value from World.Volatile.MethodFileName
    methodName = World.Volatile.MethodFileName

    ' Get the estimated run time in minutes and seconds
    methodETA = World.Volatile.LastETC
    Dim minutes 'As Integer
    Dim seconds 'As Integer
    minutes = methodETA \ 60
    seconds = methodETA Mod 60

    ' Calculate estimated end time
    estimatedEndTime = DateAdd("n", minutes, currentTime)
    estimatedEndTime = DateAdd("s", seconds, estimatedEndTime)

    ' Construct the reminder command
    Dim reminderCommand
    reminderCommand = "/remind me method " & methodName & " complete at " & FormatDateTime(estimatedEndTime, vbShortTime)

    ' Construct the message with method name, start time, and estimated end time
    Payload = "{""blocks"": [" & _
              "{" & _
              """type"": ""header""," & _
              """text"": {""type"": ""plain_text"",""text"": ""Method Started"",""emoji"": true}" & _
              "}," & _
              "{" & _
              """type"": ""section""," & _
              """fields"": [{" & _
              """type"": ""mrkdwn""," & _
              """text"": ""*Method Name :*\n" & methodName & """}" & _
              "]}," & _
              "{" & _
              """type"": ""section""," & _
              """fields"": [{" & _
              """type"": ""mrkdwn""," & _
              """text"": ""*Started:*\n" & currentTime & """}," & _
              "{" & _
              """type"": ""mrkdwn""," & _
              """text"": ""*Estimated completion: *\n" & estimatedEndTime & """}" & _
              "]}," & _
              "{" & _
              """type"": ""section""," & _
              """text"": {""type"": ""mrkdwn"",""text"": ""To set a reminder, copy and paste the following command into Slack:\n" & reminderCommand & """}" & _
              "}]}"

    objHTTP.Open "POST", WebHookUrl, False
    objHTTP.setRequestHeader "Content-Type", "application/json"
    objHTTP.send Payload
End If

4 Likes

Hi @evwolfson

Thank you so much for providing this script! I have a question, which hopefully is a simple fix that we are overlooking. Do you have an idea of how to prevent the Biomek from sending all of the slack messages at once? We have two scripts: one in the beginning of the method to signal when a method starts, and one at the end of the method to signal when that same method finishes. We tried using the “Just in time” function so that the Biomek only sends that last message when the method actually finishes but it didn’t work. Any ideas?

I haven’t run into that problem yet as I just run my Slack callout at the beginning of methods right now, but I think you’d need to enter each message into independent script then enter the following code to delay script execution

World.Globals.PauseGenerator.StallUntilETSIs 0

Likely a good idea to include this inside the “If Not Simulating” condition as to not prevent pre-run software validation.

1 Like

Thank you! It works like a charm : )