Skip to main content

The cw-rpa package provides reusable functions/common utilities for developing CW RPA bots.

Project description

RPA Library : A custom Python Library for Building (RPA) bots Solutions for Partners

RPA Library is a comprehensive Python library designed to empower partners to efficiently development of Robotic Process Automation (RPA) solutions. This library provides essential functionalities and utilities, simplifying the RPA development process. This library provides a set of modules that streamline the process of automating tasks, managing inputs, logging, and interacting with web services.

Modules Overview

The RPA Library consists of several key modules, each designed to offer specific functionalities that aid in the development of RPA solutions. Below is an overview of the available modules and their primary features.

Input Module

The Input Module is designed to handle user inputs efficiently. It provides functionalities for collecting, and processing inputs from form data.

Logger Module

The Logger Module offers advanced logging capabilities, making it easier to track the execution flow, debug issues, and maintain operational records.

HttpClient Module

The HttpClient Module simplifies interactions with web services. It provides a straightforward way to send HTTP requests and handle responses. It Support for various HTTP methods (GET, POST, PUT, DELETE, etc.) and provides mechanisms for managing authentication tokens, essential for interacting with secured APIs.

Benefits for Partners:

Faster Development: Pre-built components and utilities accelerate the development lifecycle.

Improved Code Quality: Standardized functions promote code maintainability and reusability.

Focus on Core Logic: Partners can concentrate on building the unique logic of their bots, leveraging the foundation provided by RPA Library.

Getting Started

To get started with the RPA Library, you need to install it in your Python environment. You can do this by installing it directly via pip.

Installation:

if hosted in public repo:

pip install cw_rpa

From wheel file:

pip install cw_rpa-0.1.0-py3-none-any

Example

Here are example demonstrating how to create the bot using the cw_rpa library:

Create O365 User Bot Sample Code:

    # import the rpa library modules
    from cw_rpa import (
        Logger, 
        ResultLevel, 
        Input, 
        HttpClient, 
    )

    def main():
        log = Logger()

        try:
            input = Input()
            # The following keys should be present in the fromSchema.json file
            userPrincipalName = input.get_value("userPrincipalName")
            new_user_payload = {
                "accountEnabled": input.get_value("accountEnabled"),  # Default value is True if not provided
                "displayName": input.get_value("displayName"),
                "mailNickname": input.get_value("mailNickname"),
                "userPrincipalName": userPrincipalName,
                "passwordProfile": {
                    "forceChangePasswordNextSignIn": input.get_value("forceChangePasswordNextSignIn"),
                    "password": input.get_value("password"),
                },
            }
        except Exception as e:
            log.exception(e, "An error occurred while getting input values")
            log.result_failed_message("An error occurred while getting input values")
            return

        if not userPrincipalName:
            log.error("userPrincipalName not provided")
            log.result_failed_message("userPrincipalName not provided")
            return
        
        log.info(f"creating user details for userPrincipalName: {userPrincipalName}")

        try: 

            # Create an HTTP client for making requests to the Microsoft Graph API
            http_client = HttpClient()

            # Define the endpoint for retrieving user details       
            endpoint = "https://graph.microsoft.com/v1.0/users"

            if check_user_exists(log, http_client, userPrincipalName):
                log.error(f"User already exists: {userPrincipalName}")
                log.result_failed_message(f"User already exists: {userPrincipalName}")
                return

            log.info(f"Creating user: {userPrincipalName}")
            log.result_message(ResultLevel.INFO,f"Creating user: {userPrincipalName}")

            # validating new user payload
            http_client.validate_payload(new_user_payload, ["displayName","accountEnabled", "passwordProfile.forceChangePasswordNextSignIn", "passwordProfile.password"])
            
            # Make a GET request to the endpoint
            response = http_client.third_party_integration("azure_o365").post(url=endpoint, json=new_user_payload)

            if response.status_code == 201:        
                log.info(f"User created successfully: {userPrincipalName}.")
                log.result_success_message(f"Successfully created user: {userPrincipalName}.")
                log.result_data(data=response.json())       
                
            else:
                log.error(f"Failed to create user {userPrincipalName}. Status code: {response.status_code}, Response: {response.text}")
                log.result_failed_message(f"User creation failed for user {userPrincipalName}.")

        except Exception as e:
            log.exception(e, "An unexpected error occurred while creating the user")
            log.result_failed_message(f"An error occurred while creating the user {userPrincipalName}.")
            return


    def check_user_exists(log:Logger, http_client: HttpClient, userPrincipalName: str) -> bool:
        
        try:
            # Define the endpoint for retrieving user details
            endpoint = f"https://graph.microsoft.com/v1.0/users/{userPrincipalName}"
            response = http_client.third_party_integration("azure_o365").get(endpoint)
            
            if response.status_code == 200:
                log.info(f"User exists: {userPrincipalName}")
                return True
            elif response.status_code == 404:
                log.info(f"User does not exist: {userPrincipalName}")
                return False
            else:
                log.error(f"Failed to check if user exists: {response.text}")
                return False
            
        except Exception as e:
            log.exception(e, "An error occurred while checking if user exists")
            return False


    if __name__ == "__main__":
        main()
  

Additional Resources

Custom Bot Development Documentation: https://docs.connectwise.com/ConnectWise/Asio/Hyperautomation/ConnectWise_RPA/Using_ConnectWise_RPA_Bots_in_PSA/How_to_Write_a_Custom_Bot

Sample Custom Bot Documentation: https://docs.connectwise.com/ConnectWise/Asio/Hyperautomation/ConnectWise_RPA/Using_ConnectWise_RPA_Bots_in_PSA/How_to_Write_a_Custom_Bot/Sample_Custom_Bots_-_Asio_Workflows

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

cw_rpa-1.0.0-py3-none-any.whl (18.3 kB view details)

Uploaded Python 3

File details

Details for the file cw_rpa-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: cw_rpa-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 18.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for cw_rpa-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 faa498051f57b30b6bb52f95b1403a2ecd5637ee65a434ca4624a0621f0671d8
MD5 7449d5806a530898029ecc7afc19004b
BLAKE2b-256 47576d6a45bb2196cb748b1f50cd545d3e85a522bc404cdf53912dd478c5dc55

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page