public/Publish-SocialMediaContent.ps1
function Publish-SocialMediaContent { [CmdletBinding()] param( [Parameter(Mandatory=$true)] [ValidateSet('advert','facebook','instagram')] [string]$Content, [Parameter(Mandatory=$false)] [ValidateNotNullOrEmpty()] [string]$Continent, [Parameter(Mandatory=$true)] [ValidateNotNullOrEmpty()] [string]$Path, [Parameter(Mandatory=$false)] [ValidateNotNullOrEmpty()] [string]$StartDate, [Parameter(Mandatory=$true)] [ValidateNotNullOrEmpty()] [string]$Token ) process{ $ErrorActionPreference = 'Stop' $InstagramConfig = Get-Content -Path "$Path\git-hub\sportsmonk-api\function-parameters\instagram.json" -ErrorAction Stop | ConvertFrom-Json $FacebookConfig = Get-Content -Path "$Path\git-hub\sportsmonk-api\function-parameters\facebook.json" -ErrorAction Stop | ConvertFrom-Json $InstagramPageId = $($InstagramConfig[0].PageId) $BucketName = $($InstagramConfig[0].BucketName) $FacebookPageId = ($FacebookConfig[0].PageId) if ($Content -eq 'advert') { # Set template to use $TemplatePath = "$Path\git-hub\sportsmonk-api\templates\youtube_post.txt" # Test if it exists $TemplatePathExists = Test-Path -Path $TemplatePath if ($TemplatePathExists) { # Get content of template to post $Message = Get-Content -Path $TemplatePath -Raw -ErrorAction Stop # Link to include in the feed $Link = 'https://www.youtube.com/@AISportPredicts' # Post the temple to the feed Invoke-FacebookPost -Token $Token -PageId $FacebookPageId -Message $Message -Link $Link } # if } # if if ($Content -eq 'facebook' -or ($Content -eq 'instagram')) { while ($Count -ne 1) { foreach ($Continent in $Continents) { try { if ($Content -eq 'facebook') { Invoke-AutomatedProcessHistoricalFootballFixtureMedia -SMToken $Token -Platform facebook -PageId $FacebookPageId -BucketName $BucketName -Continent $Continent -StartDate $StartDate -Path $Path } # if if ($Content -eq 'instagram') { Invoke-AutomatedProcessHistoricalFootballFixtureMedia -SMToken $Token -Platform instagram -PageId $InstagramPageId -BucketName $BucketName -Continent $Continent -StartDate $StartDate -Path $Path } # if } catch { $_.Exception.Message } # try catch } # foreach } # while } # if } # process } # function |