Search code examples
botsslackzapier

Count matching phrase message Slackbot via Zapier


I am trying to create a Slackbot that responds to slash commands, counts the number of times a given phrase occurs in a certain channel after a certain date. I have successfully set up a Zapier pipeline that captures the request, formats a search, and returns a result. Something along the lines of:

in:#[channel] “[searchText]” after:[dd/mm/yyyy] 

It seems that Zapier's Slack search integration can only return a single message. Is there a way to get the count of messages I am seeking through Zapier or an alternative approach.

I could do this through a python script but I want deliver response as a Slackbot. Zapier's code app states:

Unfortunately you cannot require external libraries or install libraries commonly referred to as "pip modules".

Which prevents me from writing a python snippet within Zapier as the code would need to use slackclient.


Solution

  • David here, from the Zapier Platform team.

    slackclient is just a wrapper for their (quite full featured, IMO) API. To use its functionality, you've got a couple of options:

    1. If you're comfortable writing javascript, create a custom private app with a "search message and count" action. You can use the slack JS sdk (since the CLI can use npm modules) or use the included z.request to write API code. Then you can return whatever data you'd like. If you go this route, you can get started with the template.
    2. If you want to stick with Python, you can use the request module (docs here) to make the aforementioned Slack API calls yourself.

    Hopefully that points you in the right direction!