webMethods.io Integration workflow: Automatically send PMs to multiple users in Discourse platform

Overview

This webMethods.io Integration workflow is triggered at a certain time and it can be used to automatically send PMs to users in Discourse community platform.

We use this example to send users a reminder to mark their topics as solved if they’ve received a solution. We noticed a lot of people would forget to do that, which kept already answered questions open. Since Discourse doesn’t have such “reminder” functionality we decided to use webMethods.io to build it (which took ~5 minutes).

Note
Currently there is no webMethods.io connector for Discourse. For workflows which work together with Discourse we are using their great API. This means that the below example will work with any application (not just Discourse) that has an API you can access.

Steps

  1. Login to your webMethods.io Integration tenant or sign up for a free trial if you’re new.

  2. Create a new project or choose an existing one.

  3. In the workflows tab, add a new Workflow.

  4. The first step is to set a reminder. Hover over the Start step and click the gear icon. Find the clock trigger and choose the best time for sending the reminder.

    As an example, I’ll set it every Monday at 1 AM:

  5. You now have to select all unsolved topics that have at least one response for a particular period of time. This you can achieve using the HTTP request connector and Discourse Search API.

    Add the HTTP Request service to the canvas by using the drag and drop feature. This automatically connects with the Clock trigger. Use the following settings to get a list with topics which:

    1. are created during a certain period of time (for this tutorial, the period of time includes topics created more than one week ago but no more than two weeks ago)
    2. have at least one reply (min_posts:2)
    3. are unsolved (status:unsolved)
    4. are opened (status:open)
    5. are in the category “Category name” (q=category-name)

    You can form your own search query with any parameters that will work for your case.

    HTTP method: Get
    URL: https://{defaultHost}/search.json?expanded=true&q=%23category-name%20status%3Aunsolved%20status%3Aopen%20before%3A{{$transform.t2.value}}%20after%3A{{$transform.t3.value}}%20in%3Afirst%20min_posts%3A2

    To get the current date, use the Transform option in the left panel and set it this way:

    Transform Name: Today date
    Transform Data: Get Current Date String
    Pattern: YYYY-MM-DD

    Create one more Transform data to get the one week ago date ({{$transform.t2.value}}):

    Transform Name: One week ago
    Transform Data: Increment date
    Date: {{$transform.t1.value}} – use the Today date value
    Input Pattern: YYYY-MM-DD
    Add Days: -7
    Output Pattern: YYYY-MM-DD

    Create one more Transform data to get the two weeks ago date ({{$transform.t3.value}}):

    Transform Name: One week ago
    Transform Data: Increment date
    Date: {{$transform.t1.value}} – use the Today date value
    Input Pattern: YYYY-MM-DD
    Add Days: -14
    Output Pattern: YYYY-MM-DD

    Use the transformed data when forming the HTTP request URL.

    Click Next and then Done to save the HTTP request.

  6. Add the Loop action to the canvas using the drag and drop feature. Click on the gear icon for settings:

    Loop type: Each item
    Source array: choose the posts array from the responseObject after the first HTTP request

  7. Double-click on the Loop action. This will open a loop canvas where you can add the action you want to execute in a loop.

  8. Add the HTTP Request service to the canvas by the drag and drop feature. Use the following Post request settings. This will send PMs to all authors:

    HTTP method: Post
    URL: https://{defaultHost}/posts.json
    Headers:

    Key: Api-Username
    Value: username
    
    Key: Api-Key
    Value: key
    

    Set Body Type: x-www-form-urlencoded
    Body:

    Name: title
    Value: Title text
    
    Name: raw
    Value: Message text, topic URL: https://{defaultHost}/t/{{$a1.currentItem.topic_id}}.
    
    Name: target_recipients
    Value: {{$a1.currentItem.username}}
    
    Name: archetype
    Value: private_message
    

    Click Done and connect the HTTP request action with the End point.

  9. Close the Loop canvas and connect the Loop action with the End point.

  10. Don’t forget to save the workflow. You can also test it using the play button in the right upper corner and review the result.

4 Likes