Genesys Cloud - Main

 View Only

Sign Up

Expand all | Collapse all

How to schedule workflow execution?

  Thread closed by the administrator, not accepting new replies.
  • 1.  How to schedule workflow execution?

    Posted 12-13-2024 08:39
    No replies, thread closed.

    Hi, any ideas how to schedule workflow execution?

    I have created a process that schedules abandoned calls as callbacks. But every morning I need to clear yesterday's callbacks as they are outdated. I have created a workflow for that, but how to schedule this workflow to be executed every morning at a fixed time before CC opening hours?

    Vidmantas


    #API/Integrations
    #ArchitectureandDesign

    ------------------------------
    Vidmantas Zygus
    Systems expert
    ------------------------------


  • 2.  RE: How to schedule workflow execution?

    Posted 12-13-2024 09:05
    No replies, thread closed.

    Hello Vidmantas, 

    You might be able to do this via triggers. I would love to see the community feedback on this though as its interesting. 

    Cheers, 



    ------------------------------
    Cameron
    Online Community Manager/Moderator
    ------------------------------



  • 3.  RE: How to schedule workflow execution?

    Posted 12-13-2024 09:13
    No replies, thread closed.

    That's understood, but all triggers are conversations, or some activity related, but no time related.



    ------------------------------
    Vidmantas Zygus
    Systems expert
    ------------------------------



  • 4.  RE: How to schedule workflow execution?

    Posted 12-14-2024 13:17
    No replies, thread closed.

    You have no way to do this initially, but what you can do is have a workflow with a delay in it that loops a lot of times.  You would just need to restart it using the API or CLI every so often.  The other option is to use a scheduled batch file on a server or desktop that runs the workflow via the CLI.  Create a text file that contains the flow ID like this: {"flowId":"dd4f556f-3131-42d3-af23-220da875cacc"} then feed that into GC using:  gc flows executions create -f inputfile.json



    ------------------------------
    Robert Wakefield-Carl
    ttec Digital
    Sr. Director - Innovation Architects
    Robert.WC@ttecdigital.com
    https://www.ttecDigital.com
    https://RobertWC.Blogspot.com
    ------------------------------



  • 5.  RE: How to schedule workflow execution?

    Posted 12-16-2024 01:05
    No replies, thread closed.

    Robert,

    can you please comment your idea  'The other option is to use a scheduled batch file on a server or desktop that runs the workflow via the CLI.  Create a text file that contains the flow ID like this: {"flowId":"dd4f556f-3131-42d3-af23-220da875cacc"} then feed that into GC using:  gc flows executions create -f inputfile.json'.  Is it documented somewhere? What API method to use?



    ------------------------------
    Vidmantas Zygus
    Systems expert
    ------------------------------



  • 6.  RE: How to schedule workflow execution?

    Posted 12-16-2024 10:05
    No replies, thread closed.

    I have created Node.js scripts which I then run on a windows server using the Task Scheduler feature in Windows at specified times. Those scripts can then run Workflows or do whatever other functionality you want.

    Example for recycling a campaign:

    I then have a batch file which runs the script:

    C:
    CD\Scripts
    node RecycleCampaign.js
    timeout 5

    Then a scheduled task to run that batch file:

     

    you can use Node.js, Python, whatever...you just have to have it installed on the server.

    Other folks are more elegant and run a scheduled app using features of AWS or other systems.

    For running a workflow you use the API POST /api/v2/flows/executions

    An example of the API call is:

    {
       "flowId": "0f8cf402-f3fb-4d5c-ba10-21d23c2d7280",
       "inputData": {"Channel": "Voice", "segment": "CommEd", "profileLanguage": "English", "profileRegion": "NA"},
       "name": "GeoTest"
    }

    You would need to wrap the rest of the Node.js around that to run it from a script.

    I used the SDK so for running the workflow you could use the SDK version postFlowsExecutions



    ------------------------------
    George Ganahl GCP, GCSME, ICCE, ICHD, etc.
    Senior Principal PS Consultant
    Genesys
    ------------------------------



  • 7.  RE: How to schedule workflow execution?

    Posted 12-16-2024 10:35
    No replies, thread closed.

    Thanks, George.

    It seems that it's the best way to start workfow using API POST /api/v2/flows/executions. I have tested it, it works perfect, so I will contact for colleagues for help, to place this script somewhere. 



    ------------------------------
    Vidmantas Zygus
    Systems expert
    ------------------------------



  • 8.  RE: How to schedule workflow execution?

    Posted 12-16-2024 10:59
    No replies, thread closed.

    I had not considered Jim's suggestion of using a campaign schedule to run a Data Action. That would probably be about the same effort as hosting a script elsewhere, and keeps it all within Genesys Cloud.



    ------------------------------
    George Ganahl GCP, GCSME, ICCE, ICHD, etc.
    Senior Principal PS Consultant
    Genesys
    ------------------------------



  • 9.  RE: How to schedule workflow execution?

    Posted 12-16-2024 15:00
    No replies, thread closed.

    Thanks George.  Too bad we can't use Node.JS in Custom Code with the time limit on excecution. 



    ------------------------------
    Robert Wakefield-Carl
    ttec Digital
    Sr. Director - Innovation Architects
    Robert.WC@ttecdigital.com
    https://www.ttecDigital.com
    https://RobertWC.Blogspot.com
    ------------------------------



  • 10.  RE: How to schedule workflow execution?

    Posted 12-17-2024 00:49
    No replies, thread closed.

    This is not documented, but you just have a batch file that has the gc command in it and use Windows Task Scheduler to run that batch file at a set time.



    ------------------------------
    Robert Wakefield-Carl
    ttec Digital
    Sr. Director - Innovation Architects
    Robert.WC@ttecdigital.com
    https://www.ttecDigital.com
    https://RobertWC.Blogspot.com
    ------------------------------



  • 11.  RE: How to schedule workflow execution?

    Posted 12-15-2024 13:39
    No replies, thread closed.

    Are you using any type of monitoring product that calls into your IVR throughout the day/evening to test?  Most of those third party products have the ability to schedule calls into an IVR so you could potentially leverage that here and setup a basic Architect flow on a test number that then calls the workflow.



    ------------------------------
    Vaun McCarthy
    ------------------------------



  • 12.  RE: How to schedule workflow execution?

    Posted 12-15-2024 23:56
    No replies, thread closed.

    Here is the idea for this:  https://genesyscloud.ideas.aha.io/ideas/SSAAOB-I-123

    Unfortunately, though in development, it is "stalled" until H2 2025



    ------------------------------
    Robert Wakefield-Carl
    ttec Digital
    Sr. Director - Innovation Architects
    Robert.WC@ttecdigital.com
    https://www.ttecDigital.com
    https://RobertWC.Blogspot.com
    ------------------------------



  • 13.  RE: How to schedule workflow execution?

    Posted 12-16-2024 10:39
    Edited by Jim Crespino 12-16-2024 10:39
    No replies, thread closed.

    Hi All,

    Scheduled triggers will ultimately be the way to accomplish this, but you'll have to wait for that feature to be delivered.  If someone asked me to try to accomplish this today, then I might suggest to look at the following.  Note, I have not set something like this up, so you might run into roadblocks.

    I would look at an Outbound Campaign as a mechanism to launch your workflow. 

    • Outbound Campaigns can be scheduled, so you can schedule the campaign to be started/stopped as specific times of day. 
    • You would need a calling list with just a single bogus phone number in the list. 
    • You would need a pre-call rule that runs against the list that has a condition that runs for every number in the list and has two actions, one to call a Data Action and then one that is "Do Not Dial" (so that the bogus number is never really dialed.)
    • The Data Action would need to call the Genesys Cloud Public API to execute the Workflow.

    So what will happen is that nightly, your outbound campaign would kick off.  The single number in the calling list would be evaluated by the rules.  The rule would call the Data Action to run your workflow and then would not dial the number.  The outbound campaign would then stop until the next scheduled start time.

    It is kind of hacky, but it should work.

    Good luck.



    ------------------------------
    Jim Crespino
    Senior Director, Developer Evangelism
    Genesys
    https://developer.genesys.com
    ------------------------------



  • 14.  RE: How to schedule workflow execution?

    Posted 12-16-2024 12:13
    Edited by Maxim Tsvetov 12-16-2024 12:39
    No replies, thread closed.

    I did setup with Agentless Outbound Campaign for couple of customer to be able to run workflows on a schedule. It works well.

    This way you can keep all the logic inside Genesys Cloud.

    *********************************************************************************************************************************************

    Here is a high-level description of how the solution works:

    {Agentless Outbound Campaign} ➔ {Call Rule Set executes Workflow} ➔ {Workflow does the job and recycles the campaign}

    1. Create an Agentless Outbound Campaign

    2. Configure the Campaign

      • Enable the "Always Running" mode to ensure the campaign remains active continuously.

    3. Add a Contact List

      • Create a contact list with a single contact (e.g., one phone number) to serve as a trigger for the campaign.

      • The phone number can be real or dummy data since no actual dialing will occur.

    4. Design a Workflow in Architect

      • Build a workflow that performs the following tasks:

        1. Executes the desired logic (e.g., data actions, data table lookups, or other processes).

        2. Waits for X minutes (customizable based on your requirements).

          1. Examples: 
            • Use Wait block with this formula to execute workflow every 5 minutes:
              • MakeDuration(0,0,5-(ToInt(Minute(GetCurrentDateTimeUtc()) % 5)),0,0)    
            • Use Wait block with this formula to execute workflow at the beginning of every hour:
              • MakeDuration(0,0,60-Minute(GetCurrentDateTimeUtc()),0,0)
        3. Recycles the campaign to restart the process. (using data action)

    5. Create a Call Rule Set

      • Configure a call rule set to manage how the campaign interacts with the workflow:

        1. First Step: Set the rule to "Do Not Dial" (prevents actual calls from being made).

        2. Second Step: Run a data action that triggers the workflow.

    6. Customize Execution Timing

      • Use the Wait action in the workflow to control how frequently the logic is executed.

      • Alternatively, use a Schedule or Schedule Group in Architect to specify exact times for running the workflow.

    *********************************************************************************************************************************************

    Other alternatives:

    Use an external scheduler to run the Workflow using REST API. This could be cron in Linux, Windows Task Scheduler, or AWS Event Bridge Scheduler.



    ------------------------------
    Maxim Tsvetov
    Principal PS Consultant
    Genesys
    ------------------------------



  • 15.  RE: How to schedule workflow execution?

    Posted 12-16-2024 12:21
    Edited by Jim Crespino 12-16-2024 12:21
    No replies, thread closed.

    Hi Maxim,

    Thanks for the confirmation that my idea would work.  Looking at your implementation, your last "Other alternatives" item got me thinking.  If you used an always running campaign, you would trickle a bogus number into the calling list any time that you needed to fire off the workflow.  So you could have any number of external "triggers" that would trickle new numbers into the calling list to run the workflow as needed.  Pretty cool!



    ------------------------------
    Jim Crespino
    Senior Director, Developer Evangelism
    Genesys
    https://developer.genesys.com
    ------------------------------



  • 16.  RE: How to schedule workflow execution?

    Posted 12-16-2024 12:37
    No replies, thread closed.

    Hi Jim,

    You are welcome.

    "Other alternatives" is for solutions that require external scheduler, so in this case no need to use Outbound campaigns.

    But yes, this solution with Outbound campaigns is easily scalable. You can add 2nd contact to the list or even create 2nd campaign with separate rule set. Or in some cases you can combine multiple logic in the same workflow.



    ------------------------------
    Maxim Tsvetov
    Principal PS Consultant
    Genesys
    ------------------------------



  • 17.  RE: How to schedule workflow execution?

    Posted 12-16-2024 12:27
    No replies, thread closed.

    Awesome! Thanks, Maxim!



    ------------------------------
    George Ganahl GCP, GCSME, ICCE, ICHD, etc.
    Senior Principal PS Consultant
    Genesys
    ------------------------------



  • 18.  RE: How to schedule workflow execution?

    Posted 12-16-2024 12:38
    No replies, thread closed.

    Glad I could help!



    ------------------------------
    Maxim Tsvetov
    Principal PS Consultant
    Genesys
    ------------------------------



  • 19.  RE: How to schedule workflow execution?

    Posted 12-17-2024 04:34
    No replies, thread closed.

    May be a good time to raise here for more votes. There are a number of Ideas for future consideration around workflow reporting. Whilst we have execution data we really need something like an interactions view for workflows with entry points, timestamps, and outcomes along with the output statement. This would also be really helpful with triggers becoming commonplace. Maybe even something similar to the Data Actions/Flow performance view with per flow data.

    https://genesyscloud.ideas.aha.io/ideas/SSA-I-557



    ------------------------------
    Richard Chandler
    Connect
    ------------------------------



  • 20.  RE: How to schedule workflow execution?

    Posted 12-17-2024 09:04
    Edited by Cameron Tomlin 12-17-2024 09:12
    No replies, thread closed.

    This is awesome Community feedback! But @Vidmantas Zygus what route did you end up taking/best answer?

    Also don't forget if you like a response a lot you can always give a nomination for community rockstar!


    ------------------------------
    Cameron
    Online Community Manager/Moderator
    ------------------------------



  • 21.  RE: How to schedule workflow execution?
    Best Answer

    Posted 12-17-2024 09:12
    No replies, thread closed.

    I have created PowerShell script and scheduled it on Windows scheduler.

    Script code generated by copilot :)

    # Enforce TLS 1.2
    [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
     
    # Define the URL and credentials for token retrieval
    $tokenUrl = "https://login.mypurecloud.ie/oauth/token"
    $clientId = "************"
    $clientSecret = "**********"
     
    # Encode the client credentials
    $encodedCredentials = [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes("${clientId}:${clientSecret}"))
     
    # Define the body for the token request
    $tokenBody = "grant_type=client_credentials"
     
    # Make the POST request to retrieve the token
    $tokenResponse = Invoke-RestMethod -Uri $tokenUrl -Method Post -Body $tokenBody -ContentType "application/x-www-form-urlencoded" -Headers @{
        Authorization = "Basic $encodedCredentials"
    }
     
    # Extract the access token
    $accessToken = $tokenResponse.access_token
     
    # Output the access token
    $accessToken
     
    # Define the URL and request body for the API call
    $apiUrl = "https://api.mypurecloud.ie/api/v2/flows/executions"
    $apiBody = @{
        flowId = "***********"
    }
     
    # Convert the body to JSON format
    $jsonApiBody = $apiBody | ConvertTo-Json
     
    # Make the POST request to the API with the Bearer token
    $apiResponse = Invoke-RestMethod -Uri $apiUrl -Method Post -Body $jsonApiBody -ContentType "application/json" -Headers @{
        Authorization = "Bearer $accessToken"
    }
     
    # Output the response
    $apiResponse


    ------------------------------
    Vidmantas Zygus
    Systems expert
    ------------------------------



  • 22.  RE: How to schedule workflow execution?

    Posted 12-17-2024 09:47
    No replies, thread closed.

    This is a great thread!  I love the collaboration around coming up with a solution to the problem.  Because I sometimes can't turn off my brain, I thought of yet another potential solution and wanted to post it here in case anyone was interested.

    The Work Automation feature of Genesys Cloud was meant to create "tasks" that are routed to live or virtual agents to complete.  These can often be long running tasks that span days/weeks/months.  So given that, I feel like Work Automation could easily be used to build a task that would wake up daily, execute, and then sleep for another day.  When it wakes up it could be sent to a queue that has no members so that an in-queue workflow could execute that would give someone the ability to execute the logic needed, including calling Data Actions.

    Someone would have to create the initial workitem using the Work Automation APIs in the API Explorer in the Genesys Cloud Developer Center, but once created, the workitem could then exist in the system happily waking, working, and sleeping as needed.

    I've only developed a small proof of concept around this where the work item would wake up every hour and do something and go back to sleep.  In my case I had it call a Data Action that called the Genesys Webhook integration to post a message into a Genesys Cloud UC chat group just so that I could know that it was executing as required.  However, I have not tested it running for weeks/months, so there may be time limits that would prevent this from being a valid solution.

    I hope that helps prompt some ideas for folks.



    ------------------------------
    Jim Crespino
    Senior Director, Developer Evangelism
    Genesys
    https://developer.genesys.com
    ------------------------------



  • 23.  RE: How to schedule workflow execution?

    Posted 12-18-2024 13:40
    Edited by Maxim Tsvetov 12-18-2024 13:41
    No replies, thread closed.

    Great idea!

    I just built a similar setup in my lab today using Workitems. Within the Workitem flow, I add a row to a contact list every 5 minutes, which serves as a log and confirmation that it actually works.

    So far, I've identified 2 limitations: 

    1)  there is a limit on number of workitem flow executions per day:

    https://developer.genesys.cloud/organization/organization/limits#task-management

    workitem.workitemflow.launch.per.day  - default is 5 but that can be increased.

    Should be fine in most cases. Alternatively, you can allow the workitem flow to run in a loop for an extended period before transitioning to a different status to limit number of executions per day.

    2) Workitems expire after 1 year. However, I believe this limitation can be overcome by adding a step to the Workitem flow that creates a new Workitem using a data action after a certain period.

    ***************

    This approach could offer customers who have purchased the Work Automation Add-On an alternative method for running scheduled workflows.



    ------------------------------
    Maxim Tsvetov
    Principal PS Consultant
    Genesys
    ------------------------------