Class/WebexApiHelperClass.psm1

class WebexApiHelperClass {
    [string] $token
    [string] $rooturl
    
    WebexApiHelperClass([string]$token, [string]$rooturl) {
        $this.token = $token
        $this.rooturl = $rooturl
    }
    
    [System.Object] GetWebexRooms() {
        $header = @{
            "Authorization" = "Bearer " + $this.token
        }
        $url = $this.rooturl + "rooms"
        $response = Invoke-RestMethod $url -Method 'GET' -Headers $header
        return $response | ConvertTo-Json 
    }

    [System.Object] GetMessages([string]$room_id) {
        $header = @{
            "Authorization" = "Bearer " + $this.token
        }
        $body = @{
            roomId = "$room_id"
        }
        $url = $this.rooturl + "messages"
        $response = Invoke-RestMethod $url -Method 'GET' -Headers $header -Body $body 
        return $response | ConvertTo-Json 
    }

    [System.Object] CreateWebexMessage([string]$recipient_type, [string]$recipient_value, [string]$message_type, [string]$message_value) {
        $header = @{
            "Authorization" = "Bearer " + $this.token;
            "Content-Type"  = "application/json";
        }
        $url = $this.rooturl + "messages"
        $body = "";
        switch ($recipient_type) {
            'Room' {  
                $body = '{"roomId" : "' + $recipient_value + '",'
            }
            'ParentMessage' { 
                $body = '{"parentId" : "' + $recipient_value + '",'
            }
            'PersonId' {
                $body = '{"toPersonId" : "' + $recipient_value + '",'
            }
            'PersonEmail' {
                $body = '{"toPersonEmail" : "' + $recipient_value + '",'
            }
        }
        switch ($message_type) {
            'Text' {  
                $body = $body + '"text" : "' + $message_value + '"}'
            }
            'Markdown' { 
                $body = $body + '"markdown" : "' + $message_value + '"}'
            }
        }
        $response = Invoke-RestMethod $url -Method 'POST' -Headers $header -Body $body 
        return $response | ConvertTo-Json 
    }
}