├── .github ├── CODE_OF_CONDUCT.md ├── CONTRIBUTING.md ├── ISSUE_TEMPLATE │ ├── bug-report.md │ └── feature_request.md ├── PULL_REQUEST_TEMPLATE.md └── SECURITY.md ├── .gitignore ├── .readthedocs.yaml ├── .vscode ├── extensions.json ├── settings.json └── tasks.json ├── CodeBuild ├── IntegrationTest │ ├── New-IntegrationInfrastructure.ps1 │ ├── Remove-IntegrationInfrastructure.ps1 │ ├── Tests │ │ └── Integration.Tests.ps1 │ └── buildspec.yml ├── UnitTestAndBuild │ ├── Publish-CFNTemplatesToS3.ps1 │ ├── Validate-CFNTemplates.Tests.ps1 │ ├── Validate-JSONConfigurations.Tests.ps1 │ ├── buildspec.yml │ ├── dotnet-install.ps1 │ └── dotnet-install.sh ├── configure_aws_credential.ps1 └── install_modules.ps1 ├── LICENSE ├── README.md ├── actions_bootstrap.ps1 ├── appveyor.yml ├── buildspec_pwsh_linux.yml ├── buildspec_pwsh_windows.yml ├── cloudformation ├── childtemplates │ ├── buckets.yml │ └── codebuild.yml ├── control_plane_parameters │ └── parameters.json ├── controlplane.yml └── manual │ └── poshgram_pipeline.yml ├── configure_aws_credential.ps1 ├── docs ├── CHANGELOG.md ├── Get-TelegramCustomEmojiStickerInfo.md ├── Get-TelegramStickerPackInfo.md ├── PoshGram-Advanced.md ├── PoshGram-Basics.md ├── PoshGram-FAQ.md ├── PoshGram-Sticker-Info.md ├── PoshGram-Telegram-API.md ├── PoshGram.md ├── Send-TelegramContact.md ├── Send-TelegramDice.md ├── Send-TelegramLocalAnimation.md ├── Send-TelegramLocalAudio.md ├── Send-TelegramLocalDocument.md ├── Send-TelegramLocalPhoto.md ├── Send-TelegramLocalSticker.md ├── Send-TelegramLocalVideo.md ├── Send-TelegramLocation.md ├── Send-TelegramMediaGroup.md ├── Send-TelegramPoll.md ├── Send-TelegramSticker.md ├── Send-TelegramTextMessage.md ├── Send-TelegramURLAnimation.md ├── Send-TelegramURLAudio.md ├── Send-TelegramURLDocument.md ├── Send-TelegramURLPhoto.md ├── Send-TelegramURLSticker.md ├── Send-TelegramURLVideo.md ├── Send-TelegramVenue.md ├── Test-BotToken.md ├── assets │ ├── PoshGram.gif │ ├── PoshGram.png │ ├── PoshGram_favicon_32x32.png │ ├── PoshGram_icon.png │ ├── telegram_custom_keyboard.png │ ├── telegram_inline_keyboard.png │ ├── telegram_share_stickers.png │ └── telegram_view_sticker_set.png ├── index.md └── requirements.txt ├── install_modules.ps1 ├── mkdocs.yml └── src ├── PSScriptAnalyzerSettings.psd1 ├── PoshGram.Settings.ps1 ├── PoshGram.build.ps1 ├── PoshGram ├── Imports.ps1 ├── PoshGram.psd1 ├── PoshGram.psm1 ├── Private │ ├── Add-EmojiDetail.ps1 │ ├── Confirm-URL.ps1 │ ├── Resolve-ShortLink.ps1 │ ├── Test-Explanation.ps1 │ ├── Test-FileExtension.ps1 │ ├── Test-FileSize.ps1 │ ├── Test-MediaGroupRequirements.ps1 │ ├── Test-PollOptions.ps1 │ ├── Test-URLExtension.ps1 │ └── Test-URLFileSize.ps1 └── Public │ ├── Get-TelegramCustomEmojiStickerInfo.ps1 │ ├── Get-TelegramStickerPackInfo.ps1 │ ├── Send-TelegramContact.ps1 │ ├── Send-TelegramDice.ps1 │ ├── Send-TelegramLocalAnimation.ps1 │ ├── Send-TelegramLocalAudio.ps1 │ ├── Send-TelegramLocalDocument.ps1 │ ├── Send-TelegramLocalPhoto.ps1 │ ├── Send-TelegramLocalSticker.ps1 │ ├── Send-TelegramLocalVideo.ps1 │ ├── Send-TelegramLocation.ps1 │ ├── Send-TelegramMediaGroup.ps1 │ ├── Send-TelegramPoll.ps1 │ ├── Send-TelegramSticker.ps1 │ ├── Send-TelegramTextMessage.ps1 │ ├── Send-TelegramURLAnimation.ps1 │ ├── Send-TelegramURLAudio.ps1 │ ├── Send-TelegramURLDocument.ps1 │ ├── Send-TelegramURLPhoto.ps1 │ ├── Send-TelegramURLSticker.ps1 │ ├── Send-TelegramURLVideo.ps1 │ ├── Send-TelegramVenue.ps1 │ └── Test-BotToken.ps1 └── Tests ├── Integration └── PoshGram-Infra.Tests.ps1 └── Unit ├── ExportedFunctions.Tests.ps1 ├── PoshGram-Module.Tests.ps1 ├── Private ├── Add-EmojiDetail.Tests.ps1 ├── Confirm-URL.Tests.ps1 ├── Resolve-ShortLink.Tests.ps1 ├── Test-Explanation.Tests.ps1 ├── Test-FileExtension.Tests.ps1 ├── Test-FileSize.Tests.ps1 ├── Test-MediaGroupRequirements.Tests.ps1 ├── Test-PollOptions.Tests.ps1 ├── Test-URLExtension.Tests.ps1 └── Test-URLFileSize.Tests.ps1 └── Public ├── Get-TelegramCustomEmojiStickerInfo.Tests.ps1 ├── Get-TelegramStickerPackInfo.Tests.ps1 ├── Send-TelegramContact.Tests.ps1 ├── Send-TelegramDice.Tests.ps1 ├── Send-TelegramLocalAnimation.Tests.ps1 ├── Send-TelegramLocalAudio.Tests.ps1 ├── Send-TelegramLocalDocument.Tests.ps1 ├── Send-TelegramLocalPhoto.Tests.ps1 ├── Send-TelegramLocalSticker.Tests.ps1 ├── Send-TelegramLocalVideo.Tests.ps1 ├── Send-TelegramLocation.Tests.ps1 ├── Send-TelegramMediaGroup.Tests.ps1 ├── Send-TelegramPoll.Tests.ps1 ├── Send-TelegramSticker.Tests.ps1 ├── Send-TelegramTextMessage.Tests.ps1 ├── Send-TelegramURLAnimation.Tests.ps1 ├── Send-TelegramURLAudio.Tests.ps1 ├── Send-TelegramURLDocument.Tests.ps1 ├── Send-TelegramURLPhoto.Tests.ps1 ├── Send-TelegramURLSticker.Tests.ps1 ├── Send-TelegramURLVideo.Tests.ps1 ├── Send-TelegramVenue.Tests.ps1 └── Test-BotToken.Tests.ps1 /.github/CODE_OF_CONDUCT.md: -------------------------------------------------------------------------------- 1 | # Contributor Covenant Code of Conduct 2 | 3 | ## Our Pledge 4 | 5 | In the interest of fostering an open and welcoming environment, we as 6 | contributors and maintainers pledge to making participation in our project and 7 | our community a harassment-free experience for everyone, regardless of age, body 8 | size, disability, ethnicity, sex characteristics, gender identity and expression, 9 | level of experience, education, socio-economic status, nationality, personal 10 | appearance, race, religion, or sexual identity and orientation. 11 | 12 | ## Our Standards 13 | 14 | Examples of behavior that contributes to creating a positive environment 15 | include: 16 | 17 | * Using welcoming and inclusive language 18 | * Being respectful of differing viewpoints and experiences 19 | * Gracefully accepting constructive criticism 20 | * Focusing on what is best for the community 21 | * Showing empathy towards other community members 22 | 23 | Examples of unacceptable behavior by participants include: 24 | 25 | * The use of sexualized language or imagery and unwelcome sexual attention or 26 | advances 27 | * Trolling, insulting/derogatory comments, and personal or political attacks 28 | * Public or private harassment 29 | * Publishing others' private information, such as a physical or electronic 30 | address, without explicit permission 31 | * Other conduct which could reasonably be considered inappropriate in a 32 | professional setting 33 | 34 | ## Our Responsibilities 35 | 36 | Project maintainers are responsible for clarifying the standards of acceptable 37 | behavior and are expected to take appropriate and fair corrective action in 38 | response to any instances of unacceptable behavior. 39 | 40 | Project maintainers have the right and responsibility to remove, edit, or 41 | reject comments, commits, code, wiki edits, issues, and other contributions 42 | that are not aligned to this Code of Conduct, or to ban temporarily or 43 | permanently any contributor for other behaviors that they deem inappropriate, 44 | threatening, offensive, or harmful. 45 | 46 | ## Scope 47 | 48 | This Code of Conduct applies both within project spaces and in public spaces 49 | when an individual is representing the project or its community. Examples of 50 | representing a project or community include using an official project e-mail 51 | address, posting via an official social media account, or acting as an appointed 52 | representative at an online or offline event. Representation of a project may be 53 | further defined and clarified by project maintainers. 54 | 55 | ## Enforcement 56 | 57 | Instances of abusive, harassing, or otherwise unacceptable behavior may be 58 | reported by contacting the project team at tech@techthoughts.info. All 59 | complaints will be reviewed and investigated and will result in a response that 60 | is deemed necessary and appropriate to the circumstances. The project team is 61 | obligated to maintain confidentiality with regard to the reporter of an incident. 62 | Further details of specific enforcement policies may be posted separately. 63 | 64 | Project maintainers who do not follow or enforce the Code of Conduct in good 65 | faith may face temporary or permanent repercussions as determined by other 66 | members of the project's leadership. 67 | 68 | ## Attribution 69 | 70 | This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, 71 | available at [https://www.contributor-covenant.org/version/1/4/code-of-conduct.html](https://www.contributor-covenant.org/version/1/4/code-of-conduct.html) 72 | 73 | [homepage]: https://www.contributor-covenant.org 74 | 75 | For answers to common questions about this code of conduct, see [https://www.contributor-covenant.org/faq](https://www.contributor-covenant.org/faq) 76 | -------------------------------------------------------------------------------- /.github/CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Contributing 2 | 3 | Thanks for your interest in contributing to the **PoshGram Project**. 4 | 5 | Whether it's a bug report, new feature, correction, or additional documentation, your feedback and contributions are appreciated. 6 | 7 | Please read through this document before submitting any issues or pull requests to ensure all the necessary information is provided to effectively respond to your bug report or contribution. 8 | 9 | Please note there is a code of conduct, please follow it in all your interactions with the project. 10 | 11 | ## Reporting Bugs/Feature Requests 12 | 13 | When filing an issue, please check [existing open](https://github.com/techthoughts2/PoshGram/issues), or [recently closed](https://github.com/techthoughts2/PoshGram/issues?q=is%3Aissue+is%3Aclosed), issues to make sure somebody else hasn't already reported the issue. Please try to include as much information as you can. Details like these are incredibly useful: 14 | 15 | * A reproducible test case or series of steps 16 | * The version of code being used 17 | * Any modifications you've made relevant to the bug 18 | * Anything unusual about your environment or deployment 19 | 20 | ## Contributing via Pull Requests 21 | 22 | Contributions via pull requests are much appreciated. Before sending a pull request, please ensure that: 23 | 24 | 1. You are working against the latest source on the *Enhancements* branch. 25 | 1. You check existing open, and recently merged, pull requests to make sure someone else hasn't addressed the problem already. 26 | 1. You open an issue to discuss any work - I'd hate for your time to be wasted. 27 | 28 | To send a pull request, please: 29 | 30 | 1. Create an issue and discuss the change. 31 | 1. Fork the repository. 32 | 1. Checkout the *Enhancements* branch 33 | 1. Modify the source; please focus on the specific change you are contributing. Please refrain from code styling changes, it will be harder to focus on your change. 34 | 1. Ensure local tests pass. 35 | 1. Commit to your fork using clear commit messages with the issue # being fixed. 36 | 1. Send a pull request, answering any default questions in the pull request interface. 37 | 38 | GitHub provides additional document on [forking a repository](https://help.github.com/articles/fork-a-repo/) and 39 | [creating a pull request](https://help.github.com/articles/creating-a-pull-request/). 40 | 41 | ## Finding contributions to work on 42 | 43 | Looking at the existing issues is a great way to find something to contribute on. As our projects, by default, use the default GitHub issue labels (enhancement/bug/duplicate/help wanted/invalid/question/wontfix), looking at any ['help wanted'](https://github.com/techthoughts2/PoshGram/issues?q=is%3Aopen+is%3Aissue+label%3A%22help+wanted%22) issues is a great place to start. 44 | 45 | ## Code of Conduct 46 | 47 | This project has a [Code of Conduct](CODE_OF_CONDUCT.md). 48 | 49 | ## Licensing 50 | 51 | See the [LICENSE](LICENSE.txt) file for our project's licensing. 52 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/bug-report.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Bug Report 3 | about: Submit a bug to PoshGram project 4 | title: 'PoshGram bug issue' 5 | labels: bug 6 | assignees: '' 7 | 8 | --- 9 | 10 | 11 | 12 | ### Expected Behavior 13 | 14 | 15 | ### Current Behavior 16 | 17 | 18 | ### Possible Solution 19 | 20 | 21 | ### Steps to Reproduce 22 | 23 | 24 | 25 | 1. 26 | 2. 27 | 3. 28 | 4. 29 | 30 | ### Context (Environment) 31 | 32 | 33 | * Operating System and version as reported by `$PSVersionTable.OS`: 34 | * PowerShell versions as reported by `$PSVersionTable.PSEdition`: 35 | 36 | 37 | 38 | ### Detailed Description 39 | 40 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/feature_request.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Feature request 3 | about: Suggest an idea for PoshGram project 4 | title: 'PoshGram Feature request' 5 | labels: 'enhancement' 6 | assignees: '' 7 | 8 | --- 9 | 10 | ### Description 11 | 12 | 13 | ### Describe the solution you'd like 14 | 15 | 16 | ### Describe any alternatives you've considered 17 | 18 | 19 | ### Additional context 20 | 21 | -------------------------------------------------------------------------------- /.github/PULL_REQUEST_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | # Pull Request 2 | 3 | **IMPORTANT: Please do not create a Pull Request without creating an issue first.** 4 | 5 | ## Issue 6 | 7 | **(REQUIRED)** Issue #: 8 | 9 | ### Closing Issues 10 | 11 | Put `closes #XXXX` in your comment to auto-close the issue that your PR fixes. 12 | 13 | ## Description 14 | 15 | Description of changes: 16 | 17 | 18 | 19 | ## License 20 | 21 | By submitting this pull request, I confirm that my contribution is made under the terms of the MIT license. 22 | -------------------------------------------------------------------------------- /.github/SECURITY.md: -------------------------------------------------------------------------------- 1 | # Security Policy 2 | 3 | ## Reporting a Vulnerability 4 | 5 | 8 | 9 | If you discover a vulnerability in PoshGram, please follow the _following process_: 10 | 11 | 1. Open a generic bug issue advising you have discovered a vulnerability. 12 | - Avoid sharing specifics or details of the vulnerability in an open GitHub issue. 13 | 2. A repo owner will reach out to you to establish a private form of communication. 14 | 3. We will evaluate the vulnerability and, if necessary, release a fix or mitigating steps to address it. We will contact you to let you know the outcome, and will credit you in the report. 15 | 16 | Please **do not disclose the vulnerability publicly** until a fix is released! 17 | 18 | 4. Once we have either a) published a fix, or b) declined to address the vulnerability for whatever reason, you are free to publicly disclose it. 19 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | Archive 2 | Artifacts 3 | cov.xml 4 | coverage.xml 5 | # OS generated files # 6 | ###################### 7 | .DS_Store 8 | .DS_Store? 9 | ._* 10 | .Spotlight-V100 11 | .Trashes 12 | ehthumbs.db 13 | Thumbs.db 14 | .pytest* -------------------------------------------------------------------------------- /.readthedocs.yaml: -------------------------------------------------------------------------------- 1 | # https://docs.readthedocs.io/en/stable/config-file/index.html 2 | 3 | # .readthedocs.yaml 4 | # Read the Docs configuration file 5 | # See https://docs.readthedocs.io/en/stable/config-file/v2.html for details 6 | 7 | # Required 8 | version: 2 9 | 10 | build: 11 | os: ubuntu-22.04 12 | tools: 13 | python: "3.11" 14 | 15 | mkdocs: 16 | configuration: mkdocs.yml 17 | 18 | python: 19 | install: 20 | - requirements: docs/requirements.txt 21 | 22 | # # Build PDF & ePub 23 | formats: all 24 | # - epub 25 | # - pdf 26 | -------------------------------------------------------------------------------- /.vscode/extensions.json: -------------------------------------------------------------------------------- 1 | { 2 | // See http://go.microsoft.com/fwlink/?LinkId=827846 3 | // for the documentation about the extensions.json format 4 | "recommendations": [ 5 | "ms-vscode.PowerShell", 6 | "ryanluker.vscode-coverage-gutters", 7 | "DavidAnson.vscode-markdownlint", 8 | "aaron-bond.better-comments", 9 | "aws-scripting-guy.cform", 10 | "kddejong.vscode-cfn-lint", 11 | "redhat.vscode-yaml" 12 | ] 13 | } 14 | -------------------------------------------------------------------------------- /.vscode/settings.json: -------------------------------------------------------------------------------- 1 | { 2 | "markdownlint.config": { 3 | "default": true, 4 | "MD007": { 5 | "indent": 4 6 | }, 7 | "no-hard-tabs": false 8 | }, 9 | // When enabled, will trim trailing whitespace when you save a file. 10 | "files.trimTrailingWhitespace": true, 11 | // specifies the location of the explicity ScriptAnalyzer settings file 12 | "powershell.scriptAnalysis.settingsPath": "PSScriptAnalyzerSettings.psd1", 13 | // specifies the PowerShell coding style used in this project (https://github.com/PoshCode/PowerShellPracticeAndStyle/issues/81) 14 | "powershell.codeFormatting.preset": "Stroustrup", 15 | "cSpell.words": [ 16 | "Allman", 17 | "alphanum", 18 | "animatedsticker", 19 | "backoff", 20 | "blockquote", 21 | "botname", 22 | "buildspec", 23 | "Burnham", 24 | "Catesta", 25 | "channelusername", 26 | "cmdlets", 27 | "customlog", 28 | "datetime", 29 | "diagvresults", 30 | "fakefile", 31 | "fakepath", 32 | "geordi", 33 | "getbytes", 34 | "getidsbot", 35 | "Gifs", 36 | "hashtable", 37 | "inlinekeyboardbutton", 38 | "jakemorrison", 39 | "Janeway", 40 | "markdownv", 41 | "Mycommand", 42 | "Nausicaan", 43 | "notmatch", 44 | "OTBS", 45 | "photourl", 46 | "poshgram", 47 | "psobject", 48 | "pwsh", 49 | "replykeyboardmarkup", 50 | "riker", 51 | "shortcode", 52 | "shortlink", 53 | "shortlinks", 54 | "slotmachine", 55 | "Starfleet", 56 | "strikethrough", 57 | "Stroustrup", 58 | "Syndec", 59 | "telegramx", 60 | "Tobu", 61 | "troi", 62 | "videosticker", 63 | "videourl", 64 | "WEBM", 65 | "webp", 66 | "wontfix", 67 | "worf" 68 | ], 69 | "cSpell.enableFiletypes": [ 70 | "!yaml", 71 | "markdown", 72 | "powershell" 73 | ] 74 | } 75 | -------------------------------------------------------------------------------- /CodeBuild/IntegrationTest/New-IntegrationInfrastructure.ps1: -------------------------------------------------------------------------------- 1 | <# 2 | This stands up any required infrastructure before the Pester integration tests run. 3 | It is invoked in the "pre_build" phase of CodeBuild. 4 | #> 5 | 6 | # $env:AWSAccountId = the AWS Account hosting the MOF Maker stack we're testing 7 | # $env:CODEBUILD_RESOLVED_SOURCE_VERSION = the CodeCommit Commit Id 8 | 9 | #$ErrorActionPreference = 'Stop' 10 | #Import-Module -Name 'AWSPowerShell.NetCore' 11 | -------------------------------------------------------------------------------- /CodeBuild/IntegrationTest/Remove-IntegrationInfrastructure.ps1: -------------------------------------------------------------------------------- 1 | <# 2 | This removes any required infrastructure after the Pester integration tests run. 3 | It is invoked whether the build succeeeds or fails, and is invoked in the 4 | "post_build" phase of CodeBuild. 5 | #> 6 | 7 | # $env:AWSAccountId = the AWS Account hosting the MOF Maker stack we're testing 8 | # $env:CODEBUILD_RESOLVED_SOURCE_VERSION = the CodeCommit Commit Id 9 | 10 | #$ErrorActionPreference = 'Stop' 11 | #Import-Module -Name 'AWSPowerShell.NetCore' 12 | -------------------------------------------------------------------------------- /CodeBuild/IntegrationTest/Tests/Integration.Tests.ps1: -------------------------------------------------------------------------------- 1 | # $env:SERVICE_NAME = name of the project 2 | # $env:ARTIFACT_S3_BUCKET = the artifact bucket used by CB 3 | # $env:AWS_ACCOUNTID = the AWS Account hosting the service under test 4 | # $env:GIT_REPO = the git repo name 5 | # $env:S3_PREFIX = the artifact prefix used by CB 6 | 7 | 8 | Describe -Name 'Infrastructure Tests' -Fixture { 9 | BeforeAll { 10 | try { 11 | $cfnExports = Get-CFNExport -ErrorAction Stop 12 | } 13 | catch { 14 | throw 15 | } 16 | $script:ServiceName = $env:SERVICE_NAME 17 | $script:AWSRegion = $env:AWS_REGION 18 | $script:AWSAccountID = $env:AWS_ACCOUNTID 19 | } #before_all 20 | 21 | Context -Name 'buckets.yml' -Fixture { 22 | 23 | It -Name 'Should create a PoshGramTestFilesBucketARN' -Test { 24 | $assertion = ($cfnExports | Where-Object { $_.Name -eq "$ServiceName-PoshGramTestFilesARN" }).Value 25 | $expected = 'arn:aws:s3::*' 26 | $assertion | Should -BeLike $expected 27 | } #it 28 | 29 | It -Name 'Should create a PoshGramURLTestFilesARN' -Test { 30 | $assertion = ($cfnExports | Where-Object { $_.Name -eq "$ServiceName-PoshGramURLTestFilesARN" }).Value 31 | $expected = 'arn:aws:s3::*' 32 | $assertion | Should -BeLike $expected 33 | } #it 34 | 35 | } #context_buckets.yml 36 | 37 | Context -Name 'codebuild.yml' -Fixture { 38 | 39 | It -Name 'Should create a EnhancementCBWindowspwshArn' -Test { 40 | $assertion = ($cfnExports | Where-Object { $_.Name -eq "$ServiceName-EnhancementCBWindowspwshArn" }).Value 41 | $expected = "arn:aws:codebuild:*" 42 | $assertion | Should -BeLike $expected 43 | } #it 44 | 45 | It -Name 'Should create a EnhancementsCBLinuxpwshARN' -Test { 46 | $assertion = ($cfnExports | Where-Object { $_.Name -eq "$ServiceName-EnhancementsCBLinuxpwshARN" }).Value 47 | $expected = "arn:aws:codebuild:*" 48 | $assertion | Should -BeLike $expected 49 | } #it 50 | 51 | It -Name 'Should create a MainCBWindowspwshARN' -Test { 52 | $assertion = ($cfnExports | Where-Object { $_.Name -eq "$ServiceName-MainCBWindowspwshARN" }).Value 53 | $expected = "arn:aws:codebuild:*" 54 | $assertion | Should -BeLike $expected 55 | } #it 56 | 57 | It -Name 'Should create a MainCBLinuxpwshARN' -Test { 58 | $assertion = ($cfnExports | Where-Object { $_.Name -eq "$ServiceName-MainCBLinuxpwshARN" }).Value 59 | $expected = "arn:aws:codebuild:*" 60 | $assertion | Should -BeLike $expected 61 | } #it 62 | 63 | } #context_codebuild.yml 64 | 65 | # Context -Name 'codepipeline.yml' -Fixture { 66 | 67 | # It -Name 'Should create a PoshGramEnhancementsCICDPipelineName' -Test { 68 | # $assertion = ($cfnExports | Where-Object { $_.Name -eq "$ServiceName-PoshGramEnhancementsCICDPipelineName" }).Value 69 | # $expected = "$ServiceName-Enhancements-CodePipeline" 70 | # $assertion | Should -BeLike $expected 71 | # } #it 72 | 73 | # It -Name 'Should create a PoshGrammainCICDPipelineName' -Test { 74 | # $assertion = ($cfnExports | Where-Object { $_.Name -eq "$ServiceName-PoshGrammainCICDPipelineName" }).Value 75 | # $expected = "$ServiceName-main-CodePipeline" 76 | # $assertion | Should -BeLike $expected 77 | # } #it 78 | 79 | # } #context_codepipeline.yml 80 | 81 | } #describe_infra_tests 82 | -------------------------------------------------------------------------------- /CodeBuild/IntegrationTest/buildspec.yml: -------------------------------------------------------------------------------- 1 | # https://docs.aws.amazon.com/codebuild/latest/userguide/build-spec-ref.html 2 | # https://docs.aws.amazon.com/codebuild/latest/userguide/getting-started-cli-create-build-spec.html 3 | # https://docs.aws.amazon.com/codebuild/latest/userguide/available-runtimes.html 4 | # https://docs.aws.amazon.com/codebuild/latest/userguide/runtime-versions.html 5 | 6 | version: 0.2 7 | 8 | phases: 9 | install: 10 | runtime-versions: 11 | dotnet: 6.0 12 | 13 | commands: 14 | - echo Configure AWS defaults using the configuration script added to the Docker Image. 15 | - pwsh -command './CodeBuild/configure_aws_credential.ps1' 16 | - echo Installing PowerShell Modules from S3 17 | - pwsh -command './CodeBuild/install_modules.ps1' 18 | 19 | pre_build: 20 | commands: 21 | - pwsh -command '$PSVersionTable' 22 | - pwsh -command 'Get-ChildItem env:' 23 | - echo Pre-Build started on `date` 24 | - pwsh -command '& ./CodeBuild/IntegrationTest/New-IntegrationInfrastructure.ps1' 25 | 26 | build: 27 | commands: 28 | - pwsh -command ' 29 | Import-Module Pester; 30 | $pesterConfiguration = [PesterConfiguration]::new(); 31 | $pesterConfiguration.Run.Exit = $true; 32 | $pesterConfiguration.Run.Path = "./CodeBuild/IntegrationTest/Tests"; 33 | $pesterConfiguration.Output.Verbosity = "Detailed"; 34 | Invoke-Pester -Configuration $pesterConfiguration' 35 | finally: 36 | - pwsh -command '& ./CodeBuild/IntegrationTest/Remove-IntegrationInfrastructure.ps1' 37 | -------------------------------------------------------------------------------- /CodeBuild/UnitTestAndBuild/Publish-CFNTemplatesToS3.ps1: -------------------------------------------------------------------------------- 1 | $ErrorActionPreference = 'Stop' 2 | $ProgressPreference = 'SilentlyContinue' 3 | 4 | if ([String]::IsNullOrWhiteSpace($env:ARTIFACT_S3_BUCKET)) { 5 | throw 'The environment variable ARTIFACT_S3_BUCKET must be configured.' 6 | } 7 | 8 | if ([String]::IsNullOrWhiteSpace($env:S3_KEY_PREFIX)) { 9 | throw 'The environment variable S3_KEY_PREFIX must be configured.' 10 | } 11 | 12 | # # Paths are based from the root of the GIT repository 13 | # $paths = @( 14 | # './cloudformation' 15 | # ) 16 | 17 | # if ($env:REGIONAL_BUCKET) { 18 | # $artifactBucket = $env:REGIONAL_BUCKET 19 | # } 20 | # else { 21 | # $artifactBucket = $env:ARTIFACT_S3_BUCKET 22 | # } 23 | 24 | # foreach ($path in $paths) { 25 | # Write-Host "Processing CloudFormation Templates in '$path':" 26 | # # All CloudFormation Templates to publish are located in or below the "./CloudFormation" folder 27 | # foreach ($file in (Get-ChildItem -Path $path -Recurse -File -Filter "*.yml")) { 28 | 29 | # '' # Blank line to separate CodeBuild Output 30 | 31 | # # Calculate the S3 Key Prefix, keeping the correct Folder Structure 32 | # if ($file.Name -like '*-ControlPlane.yml') { 33 | # $s3KeyPrefix = '{0}/CloudFormation/{1}' -f $env:S3_KEY_PREFIX, $file.Directory.Name 34 | # } 35 | # elseif ($file.Directory.Name -eq 'ChildTemplates') { 36 | # # Find the parent template path 37 | # $parentPath = Split-Path -Path $file.Directory 38 | # $templatePath = Split-Path -Path $parentPath -Leaf 39 | # $s3KeyPrefix = '{0}/CloudFormation/{1}/{2}' -f $env:S3_KEY_PREFIX, $templatePath, $file.Directory.Name 40 | # } 41 | # elseif ($file.Directory.Name -eq 'Manual') { 42 | # Write-Host 'Manually deployed CFN detected. Skipping.' 43 | # continue 44 | # } 45 | # else { 46 | # throw 'Unexpected directory encountered inside CloudFormation folder' 47 | # } 48 | 49 | # $s3Key = '{0}/{1}' -f $s3KeyPrefix, $file.Name 50 | # [string]$endPoint = "https://s3.$env:AWSRegion" + ".amazonaws.com" 51 | 52 | # Write-Host "ENDPOINT: $endPoint" 53 | # Write-Host "BUCKET: $artifactBucket" 54 | # Write-Host "KEY: $s3Key" 55 | # $writeS3ObjectSplat = @{ 56 | # BucketName = $artifactBucket 57 | # Key = $s3Key 58 | # File = $file.FullName 59 | # Region = $env:AWSRegion 60 | # EndpointUrl = $endPoint 61 | # } 62 | # Write-S3Object @writeS3ObjectSplat 63 | 64 | # Remove-Variable -Name @('s3Key', 's3KeyPrefix') -ErrorAction SilentlyContinue 65 | # } 66 | # } 67 | # Update the ControlPlane Parameters JSON files with the target Artifact S3 Bucket. 68 | # All JSON files will be updated, however the deployment CodePipeline is hard coded 69 | # to a specific JSON file so other deployments will not be affected. 70 | foreach ($controlPlaneFolder in (Get-ChildItem -Path './cloudformation' -Recurse -Filter '*control_plane_parameters' -Directory)) { 71 | foreach ($file in (Get-ChildItem -Path $controlPlaneFolder.FullName -Filter '*.json' -Recurse)) { 72 | $fileContent = Get-Content -Path $file.FullName -Raw | ConvertFrom-Json 73 | 74 | $fileContent.Parameters.ArtifactS3Bucket = $env:ARTIFACT_S3_BUCKET 75 | 76 | $fileContent.Parameters.ArtifactS3KeyPrefix = $env:S3_KEY_PREFIX 77 | 78 | $fileContent | ConvertTo-Json -Compress -Depth 6 | Out-File -FilePath $file.FullName -Force 79 | } 80 | } -------------------------------------------------------------------------------- /CodeBuild/UnitTestAndBuild/Validate-CFNTemplates.Tests.ps1: -------------------------------------------------------------------------------- 1 | $paths = @( 2 | 'cloudformation' 3 | ) 4 | $files = Get-ChildItem -Path $paths -Recurse -Filter '*.yml' 5 | $ErrorActionPreference = 'Stop' 6 | 7 | Describe 'CloudFormation Template Validation' { 8 | 9 | Context -Name 'CloudFormation Templates' { 10 | Context -Name '<_.Name>' -Foreach $files { 11 | It 'is valid CFN' { 12 | { Test-CFNTemplate -TemplateBody (Get-Content -Path $_.FullName -Raw) } | Should -Not -Throw 13 | } #it 14 | } 15 | } #context_cfn_templates 16 | 17 | } #describe_cfn_templates 18 | -------------------------------------------------------------------------------- /CodeBuild/UnitTestAndBuild/Validate-JSONConfigurations.Tests.ps1: -------------------------------------------------------------------------------- 1 | $paths = @( 2 | 'cloudformation' 3 | ) 4 | $files = Get-ChildItem -Path $paths -File -Recurse -Filter '*.json' 5 | $ErrorActionPreference = 'Stop' 6 | 7 | Describe -Name 'JSON Configuration File Validation' { 8 | 9 | Context -Name 'JSON Parameter Files' { 10 | Context -Name '<_.Name>' -Foreach $files { 11 | It 'is valid JSON' { 12 | { $null = ConvertFrom-Json -InputObject (Get-Content -Path $_.FullName -Raw) } | Should -Not -Throw 13 | } #it 14 | } 15 | } #context_json_parameter_files 16 | 17 | } #describe_json_configuration_file_validation 18 | -------------------------------------------------------------------------------- /CodeBuild/UnitTestAndBuild/buildspec.yml: -------------------------------------------------------------------------------- 1 | # https://docs.aws.amazon.com/codebuild/latest/userguide/build-spec-ref.html 2 | # https://docs.aws.amazon.com/codebuild/latest/userguide/getting-started-cli-create-build-spec.html 3 | # https://docs.aws.amazon.com/codebuild/latest/userguide/available-runtimes.html 4 | # 5 | 6 | version: 0.2 7 | 8 | phases: 9 | install: 10 | runtime-versions: 11 | dotnet: 6.0 12 | # python: 3.9 13 | 14 | commands: 15 | # Check PowerShell Version 16 | - pwsh -command '$PSVersionTable' 17 | 18 | # Check available variables in the build 19 | # - pwsh -command 'Get-Variable' 20 | 21 | # Check available environment variables in the build 22 | # - pwsh -command 'Get-ChildItem env:' 23 | 24 | # Configure AWS defaults using the configuration script added to the Docker Image. 25 | - pwsh -command './CodeBuild/configure_aws_credential.ps1' 26 | 27 | # Installing PowerShell Modules from PSGallery 28 | - pwsh -command './CodeBuild/install_modules.ps1' 29 | 30 | # Install Python packages 31 | # - pip install pip -U 32 | # - pip install -r ./lambdafunctions/python/requirements.txt 33 | 34 | pre_build: 35 | commands: 36 | # https://docs.microsoft.com/en-us/dotnet/core/tools/dotnet-install-script 37 | # - pwsh -command '& ./CodeBuild/UnitTestAndBuild/dotnet-install.ps1 -Channel LTS' 38 | # - ./CodeBuild/UnitTestAndBuild/dotnet-install.sh --channel LTS 39 | 40 | # Validate CloudFormation Templates 41 | - pwsh -command ' 42 | Import-Module Pester; 43 | $pesterConfiguration = [PesterConfiguration]::new(); 44 | $pesterConfiguration.Run.Exit = $true; 45 | $pesterConfiguration.Run.Path = "./CodeBuild/UnitTestAndBuild/Validate-CFNTemplates.Tests.ps1"; 46 | $pesterConfiguration.Output.Verbosity = "Detailed"; 47 | Invoke-Pester -Configuration $pesterConfiguration' 48 | 49 | # Validate Json files 50 | - pwsh -command ' 51 | Import-Module Pester; 52 | $pesterConfiguration = [PesterConfiguration]::new(); 53 | $pesterConfiguration.Run.Exit = $true; 54 | $pesterConfiguration.Run.Path = "./CodeBuild/UnitTestAndBuild/Validate-JSONConfigurations.Tests.ps1"; 55 | $pesterConfiguration.Output.Verbosity = "Detailed"; 56 | Invoke-Pester -Configuration $pesterConfiguration' 57 | build: 58 | commands: 59 | # Run Python unit tests 60 | # - python -m pytest lambdafunctions/python/tests -v 61 | 62 | # Publish cloudformation templates to S3 63 | - pwsh -command '& ./CodeBuild/UnitTestAndBuild/Publish-CFNTemplatesToS3.ps1' 64 | 65 | # Running Invoke-Build against each PowerShell AWS Lambda Function 66 | # - pwsh -command 'Get-ChildItem -Path './lambdafunctions/PowerShell' -Filter '*.build.ps1' -File -Recurse | ForEach-Object {Invoke-Build -File $_.FullName}' 67 | 68 | - cd $CODEBUILD_SRC_DIR/cloudformation 69 | - aws cloudformation package --template-file controlplane.yml --s3-bucket $ARTIFACT_S3_BUCKET --output-template-file controlplane-packaged.yml 70 | 71 | post_build: 72 | commands: 73 | - echo THE POSTBUILD 74 | 75 | artifacts: 76 | files: 77 | - cloudformation/**/* 78 | - CodeBuild/**/* 79 | -------------------------------------------------------------------------------- /CodeBuild/configure_aws_credential.ps1: -------------------------------------------------------------------------------- 1 | <# 2 | .SYNOPSIS 3 | This script is used in AWS CodeBuild to configure the default AWS Credentials for use by the AWS CLI and the AWS Powershell module. 4 | .DESCRIPTION 5 | By default, the AWS PowerShell Module does not know about looking up an AWS Container's credentials path, so this works around that issue. 6 | .NOTES 7 | This script enables AWSPowerShell cmdlets in your CodeBuild to interact with and access other AWS resources in your account. 8 | #> 9 | 'Configuring AWS credentials' 10 | 11 | ' - Retrieving temporary credentials from metadata' 12 | $uri = 'http://169.254.170.2{0}' -f $env:AWS_CONTAINER_CREDENTIALS_RELATIVE_URI 13 | $sts = Invoke-RestMethod -UseBasicParsing -Uri $uri 14 | 15 | ' - Setting default AWS Credential' 16 | $credentialsFile = "$env:HOME\.aws\credentials" 17 | $null = New-Item -Path $credentialsFile -Force 18 | 19 | '[default]' | Out-File -FilePath $credentialsFile -Append 20 | 'aws_access_key_id={0}' -f $sts.AccessKeyId | Out-File -FilePath $credentialsFile -Append 21 | 'aws_secret_access_key={0}' -f $sts.SecretAccessKey | Out-File -FilePath $credentialsFile -Append 22 | 'aws_session_token={0}' -f $sts.Token | Out-File -FilePath $credentialsFile -Append 23 | 24 | ' - Setting default AWS Region' 25 | 'region={0}' -f $env:AWS_DEFAULT_REGION | Out-File -FilePath $credentialsFile -Append 26 | 27 | ' - AWS credentials configured' 28 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2024 Jake Morrison 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /actions_bootstrap.ps1: -------------------------------------------------------------------------------- 1 | # Bootstrap dependencies 2 | 3 | [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12 4 | 5 | # https://docs.microsoft.com/powershell/module/packagemanagement/get-packageprovider 6 | # Get-PackageProvider -Name Nuget -ForceBootstrap | Out-Null 7 | 8 | # Install-Module -Name PowerShellGet -RequiredVersion 2.2.4.1 -Force -Scope CurrentUser 9 | 10 | # https://docs.microsoft.com/powershell/module/powershellget/set-psrepository 11 | # Set-PSRepository -Name PSGallery -InstallationPolicy Trusted 12 | 13 | # List of PowerShell Modules required for the build 14 | $modulesToInstall = [System.Collections.ArrayList]::new() 15 | # https://github.com/pester/Pester 16 | $null = $modulesToInstall.Add(([PSCustomObject]@{ 17 | ModuleName = 'Pester' 18 | ModuleVersion = '5.5.0' 19 | })) 20 | # https://github.com/nightroman/Invoke-Build 21 | $null = $modulesToInstall.Add(([PSCustomObject]@{ 22 | ModuleName = 'InvokeBuild' 23 | ModuleVersion = '5.10.4' 24 | })) 25 | # https://github.com/PowerShell/PSScriptAnalyzer 26 | $null = $modulesToInstall.Add(([PSCustomObject]@{ 27 | ModuleName = 'PSScriptAnalyzer' 28 | ModuleVersion = '1.21.0' 29 | })) 30 | # https://github.com/techthoughts2/pwshEmojiExplorer 31 | $null = $modulesToInstall.Add(([PSCustomObject]@{ 32 | ModuleName = 'pwshEmojiExplorer' 33 | ModuleVersion = '0.8.2' 34 | })) 35 | # https://github.com/PowerShell/platyPS 36 | # older version used due to: https://github.com/PowerShell/platyPS/issues/457 37 | $null = $modulesToInstall.Add(([PSCustomObject]@{ 38 | ModuleName = 'platyPS' 39 | ModuleVersion = '0.12.0' 40 | })) 41 | 42 | 'Setting PSGallery to trusted' 43 | Set-PSRepository -Name PSGallery -InstallationPolicy Trusted 44 | 45 | 'Installing PowerShell Modules' 46 | foreach ($module in $modulesToInstall) { 47 | $installSplat = @{ 48 | Name = $module.ModuleName 49 | RequiredVersion = $module.ModuleVersion 50 | Repository = 'PSGallery' 51 | Force = $true 52 | ErrorAction = 'Stop' 53 | } 54 | try { 55 | Install-Module @installSplat 56 | Import-Module -Name $module.ModuleName -ErrorAction Stop 57 | ' - Successfully installed {0}' -f $module.ModuleName 58 | } 59 | catch { 60 | $message = 'Failed to install {0}' -f $module.ModuleName 61 | " - $message" 62 | throw $message 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /appveyor.yml: -------------------------------------------------------------------------------- 1 | version: 1.0.{build} 2 | 3 | # https://www.appveyor.com/docs/build-configuration/ 4 | # https://www.appveyor.com/docs/build-configuration/#specializing-matrix-job-configuration 5 | # https://www.appveyor.com/docs/appveyor-yml/ 6 | 7 | branches: 8 | only: 9 | - main 10 | - Enhancements 11 | 12 | # Do not build on tags (GitHub, Bitbucket, GitLab, Gitea) 13 | skip_tags: true 14 | 15 | skip_commits: 16 | files: 17 | - docs/* 18 | - media/* 19 | message: /updated readme.*|update readme.*s/ 20 | 21 | image: 22 | - macOS 23 | 24 | init: 25 | - pwsh: $PSVersionTable 26 | install: 27 | - pwsh: . .\actions_bootstrap.ps1 28 | build_script: 29 | - pwsh: Invoke-Build -File .\src\PoshGram.build.ps1 -Task TestLocal 30 | -------------------------------------------------------------------------------- /buildspec_pwsh_linux.yml: -------------------------------------------------------------------------------- 1 | # This is a simple CodeBuild build file for PowerShell. 2 | # - pre_build step will ensure the Module Name / Version has not previously been built for production (plans to add this at a later time) 3 | # - build step will perform Clean, ValidateRequirements, Analyze, Test, CreateHelp, Build, Archive 4 | # https://docs.aws.amazon.com/codebuild/latest/userguide/build-env-ref-available.html 5 | # https://docs.aws.amazon.com/codebuild/latest/userguide/build-spec-ref.html#runtime-versions-buildspec-file 6 | # https://docs.aws.amazon.com/codebuild/latest/userguide/test-reporting.html 7 | 8 | version: 0.2 9 | 10 | phases: 11 | install: 12 | runtime-versions: 13 | dotnet: 6.0 14 | 15 | commands: 16 | - pwsh -command './configure_aws_credential.ps1' 17 | - pwsh -command './install_modules.ps1' 18 | pre_build: 19 | commands: 20 | - pwsh -command '$PSVersionTable' 21 | # uncomment the line below to explore what modules/variables/env variables are available in the build image 22 | # - pwsh -command 'Get-Module -ListAvailable; (Get-Variable).GetEnumerator() | Sort-Object Name | Out-String; (Get-ChildItem env:*).GetEnumerator() | Sort-Object Name | Out-String' 23 | - pwsh -command 'New-Item -Path /Test -ItemType Directory | Out-Null' 24 | - pwsh -command 'New-Item -Path /Test/Animation -ItemType Directory | Out-Null' 25 | - pwsh -command 'New-Item -Path /Test/Audio -ItemType Directory | Out-Null' 26 | - pwsh -command 'New-Item -Path /Test/Documents -ItemType Directory | Out-Null' 27 | - pwsh -command 'New-Item -Path /Test/PhotoGroup -ItemType Directory | Out-Null' 28 | - pwsh -command 'New-Item -Path /Test/Photos -ItemType Directory | Out-Null' 29 | - pwsh -command 'New-Item -Path /Test/VideoGroup -ItemType Directory | Out-Null' 30 | - pwsh -command 'New-Item -Path /Test/Videos -ItemType Directory | Out-Null' 31 | - pwsh -command 'New-Item -Path /Test/Stickers -ItemType Directory | Out-Null' 32 | - aws s3 cp s3://$TESTFILES_S3_BUCKET/jean.gif /Test/Animation/jean.gif --quiet 33 | - aws s3 cp s3://$TESTFILES_S3_BUCKET/Tobu-_-Syndec-Dusk-_NCS-Release_-YouTube.mp3 /Test/Audio/Tobu-_-Syndec-Dusk-_NCS-Release_-YouTube.mp3 --quiet 34 | - aws s3 cp s3://$TESTFILES_S3_BUCKET/TestAudio.mp3 /Test/Audio/TestAudio.mp3 --quiet 35 | - aws s3 cp s3://$TESTFILES_S3_BUCKET/customlog.txt /Test/Documents/customlog.txt --quiet 36 | - aws s3 cp s3://$TESTFILES_S3_BUCKET/customlog2.txt /Test/Documents/customlog2.txt --quiet 37 | - aws s3 cp s3://$TESTFILES_S3_BUCKET/beverly.jpg /Test/PhotoGroup/beverly.jpg --quiet 38 | - aws s3 cp s3://$TESTFILES_S3_BUCKET/data.jpg /Test/PhotoGroup/data.jpg --quiet 39 | - aws s3 cp s3://$TESTFILES_S3_BUCKET/geordi.jpg /Test/PhotoGroup/geordi.jpg --quiet 40 | - aws s3 cp s3://$TESTFILES_S3_BUCKET/picard.jpg /Test/PhotoGroup/picard.jpg --quiet 41 | - aws s3 cp s3://$TESTFILES_S3_BUCKET/riker.PNG /Test/PhotoGroup/riker.PNG --quiet 42 | - aws s3 cp s3://$TESTFILES_S3_BUCKET/troi.jpg /Test/PhotoGroup/troi.jpg --quiet 43 | - aws s3 cp s3://$TESTFILES_S3_BUCKET/worf.jpg /Test/PhotoGroup/worf.jpg --quiet 44 | - aws s3 cp s3://$TESTFILES_S3_BUCKET/Photo.jpg /Test/Photos/Photo.jpg --quiet 45 | - aws s3 cp s3://$TESTFILES_S3_BUCKET/first_contact.mp4 /Test/VideoGroup/first_contact.mp4 --quiet 46 | - aws s3 cp s3://$TESTFILES_S3_BUCKET/root_beer.mp4 /Test/VideoGroup/root_beer.mp4 --quiet 47 | - aws s3 cp s3://$TESTFILES_S3_BUCKET/Intro.mp4 /Test/Videos/Intro.mp4 --quiet 48 | - aws s3 cp s3://$TESTFILES_S3_BUCKET/picard.webp /Test/Stickers/picard.webp --quiet 49 | - aws s3 cp s3://$TESTFILES_S3_BUCKET/picard.webp /Test/Stickers/videosticker.webm --quiet 50 | - aws s3 cp s3://$TESTFILES_S3_BUCKET/picard.webp /Test/Stickers/videosticker2.webm --quiet 51 | - aws s3 cp s3://$TESTFILES_S3_BUCKET/picard.webp /Test/Stickers/animatedsticker.tgs --quiet 52 | #- pwsh -command 'Invoke-Build -File .\src\PoshGram.build.Settings.ps1 -Task ValidateUniqueModuleVersion' 53 | build: 54 | commands: 55 | - pwsh -command 'Invoke-Build -File .\src\PoshGram.build.ps1' 56 | artifacts: 57 | files: 58 | - '**/*' 59 | base-directory: 'src/Archive' 60 | -------------------------------------------------------------------------------- /buildspec_pwsh_windows.yml: -------------------------------------------------------------------------------- 1 | # This is a simple CodeBuild build file for PowerShell. 2 | # - pre_build step will ensure the Module Name / Version has not previously been built for production (plans to add this at a later time) 3 | # - build step will perform Clean, ValidateRequirements, Analyze, Test, CreateHelp, Build, Archive 4 | # https://docs.aws.amazon.com/codebuild/latest/userguide/build-env-ref-available.html 5 | # https://docs.aws.amazon.com/codebuild/latest/userguide/build-spec-ref.html#runtime-versions-buildspec-file 6 | # https://docs.aws.amazon.com/codebuild/latest/userguide/test-reporting.html 7 | 8 | version: 0.2 9 | 10 | phases: 11 | install: 12 | runtime-versions: 13 | dotnet: 6.0 14 | 15 | commands: 16 | - pwsh -command '.\configure_aws_credential.ps1' 17 | - '& "C:\Program Files\PowerShell\7\pwsh.exe" -command ''.\install_modules.ps1''' 18 | pre_build: 19 | commands: 20 | - pwsh -command '$PSVersionTable' 21 | # uncomment the line below to explore what modules/variables/env variables are available in the build image 22 | # - pwsh -command 'Get-Module -ListAvailable; (Get-Variable).GetEnumerator() | Sort-Object Name | Out-String; (Get-ChildItem env:*).GetEnumerator() | Sort-Object Name | Out-String' 23 | - pwsh -command 'New-Item -Path C:\Test -ItemType Directory | Out-Null' 24 | - pwsh -command 'New-Item -Path C:\Test\Animation -ItemType Directory | Out-Null' 25 | - pwsh -command 'New-Item -Path C:\Test\Audio -ItemType Directory | Out-Null' 26 | - pwsh -command 'New-Item -Path C:\Test\Documents -ItemType Directory | Out-Null' 27 | - pwsh -command 'New-Item -Path C:\Test\PhotoGroup -ItemType Directory | Out-Null' 28 | - pwsh -command 'New-Item -Path C:\Test\Photos -ItemType Directory | Out-Null' 29 | - pwsh -command 'New-Item -Path C:\Test\VideoGroup -ItemType Directory | Out-Null' 30 | - pwsh -command 'New-Item -Path C:\Test\Videos -ItemType Directory | Out-Null' 31 | - pwsh -command 'New-Item -Path C:\Test\Stickers -ItemType Directory | Out-Null' 32 | - aws s3 cp s3://$TESTFILES_S3_BUCKET/jean.gif C:\Test\Animation\jean.gif --quiet 33 | - aws s3 cp s3://$TESTFILES_S3_BUCKET/Tobu-_-Syndec-Dusk-_NCS-Release_-YouTube.mp3 C:\Test\Audio\Tobu-_-Syndec-Dusk-_NCS-Release_-YouTube.mp3 --quiet 34 | - aws s3 cp s3://$TESTFILES_S3_BUCKET/TestAudio.mp3 C:\Test\Audio\TestAudio.mp3 --quiet 35 | - aws s3 cp s3://$TESTFILES_S3_BUCKET/customlog.txt C:\Test\Documents\customlog.txt --quiet 36 | - aws s3 cp s3://$TESTFILES_S3_BUCKET/customlog2.txt C:\Test\Documents\customlog2.txt --quiet 37 | - aws s3 cp s3://$TESTFILES_S3_BUCKET/beverly.jpg C:\Test\PhotoGroup\beverly.jpg --quiet 38 | - aws s3 cp s3://$TESTFILES_S3_BUCKET/data.jpg C:\Test\PhotoGroup\data.jpg --quiet 39 | - aws s3 cp s3://$TESTFILES_S3_BUCKET/geordi.jpg C:\Test\PhotoGroup\geordi.jpg --quiet 40 | - aws s3 cp s3://$TESTFILES_S3_BUCKET/picard.jpg C:\Test\PhotoGroup\picard.jpg --quiet 41 | - aws s3 cp s3://$TESTFILES_S3_BUCKET/riker.PNG C:\Test\PhotoGroup\riker.PNG --quiet 42 | - aws s3 cp s3://$TESTFILES_S3_BUCKET/troi.jpg C:\Test\PhotoGroup\troi.jpg --quiet 43 | - aws s3 cp s3://$TESTFILES_S3_BUCKET/worf.jpg C:\Test\PhotoGroup\worf.jpg --quiet 44 | - aws s3 cp s3://$TESTFILES_S3_BUCKET/Photo.jpg C:\Test\Photos\Photo.jpg --quiet 45 | - aws s3 cp s3://$TESTFILES_S3_BUCKET/first_contact.mp4 C:\Test\VideoGroup\first_contact.mp4 --quiet 46 | - aws s3 cp s3://$TESTFILES_S3_BUCKET/root_beer.mp4 C:\Test\VideoGroup\root_beer.mp4 --quiet 47 | - aws s3 cp s3://$TESTFILES_S3_BUCKET/Intro.mp4 C:\Test\Videos\Intro.mp4 --quiet 48 | - aws s3 cp s3://$TESTFILES_S3_BUCKET/picard.webp C:\Test\Stickers\picard.webp --quiet 49 | - aws s3 cp s3://$TESTFILES_S3_BUCKET/picard.webp C:\Test\Stickers\videosticker.webm --quiet 50 | - aws s3 cp s3://$TESTFILES_S3_BUCKET/picard.webp C:\Test\Stickers\videosticker2.webm --quiet 51 | - aws s3 cp s3://$TESTFILES_S3_BUCKET/picard.webp C:\Test\Stickers\animatedsticker.tgs --quiet 52 | #- '& "C:\Program Files\PowerShell\6\pwsh.exe" -command ''Invoke-Build -File .\src\PoshGram.build.Settings.ps1 -Task ValidateUniqueModuleVersion''' 53 | - pwsh -command '$PSVersionTable' 54 | build: 55 | commands: 56 | - pwsh -command 'Start-Sleep -Seconds 630' 57 | - pwsh -command 'Invoke-Build -File .\src\PoshGram.build.ps1' 58 | artifacts: 59 | files: 60 | - '**/*' 61 | base-directory: 'src\Archive' 62 | -------------------------------------------------------------------------------- /cloudformation/control_plane_parameters/parameters.json: -------------------------------------------------------------------------------- 1 | { 2 | "Parameters": { 3 | "ServiceName": "PoshGram", 4 | "ArtifactS3Bucket": "will be replaced during CodeBuild process", 5 | "ArtifactS3KeyPrefix": "will be replaced during CodeBuild process", 6 | "CodeBuildBadgeEnabled": "true", 7 | "GitHubOwner": "techthoughts2", 8 | "GitHubRepositoryName": "PoshGram", 9 | "RepositoryUrl": "https://github.com/techthoughts2/PoshGram", 10 | "CodeBuildTimeoutInMinutes": "60" 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /cloudformation/controlplane.yml: -------------------------------------------------------------------------------- 1 | # Master Control Plane cloudformation Template - Used to deploy the service to child AWS Accounts. 2 | # This control plane does the actual DEPLOYING, but it does so by referencing the child templates via AWS::cloudformation::Stack 3 | # Hi - you want a new parameter - great! 4 | # 1 - Update the parameter JSONS (ControlPlane-Parameters\*.json) 5 | # 2 - Update two locations in ControlPlane 6 | # 3 - Update two locations in ChildTemplates 7 | 8 | --- 9 | AWSTemplateFormatVersion: "2010-09-09" 10 | 11 | Description: "PoshGram: Control Plane" 12 | 13 | Parameters: 14 | 15 | ServiceName: 16 | Type: String 17 | Description: The name of the service being deployed. 18 | 19 | # LMFunctionS3KeypwshEEUnicodeVersionMonitor: 20 | # Type: String 21 | # Description: S3 Key for the PubXMLMonitor Lambda function(s) zip file 22 | 23 | # LMFunctionHandlerpwshEEUnicodeVersionMonitor: 24 | # Type: String 25 | # Description: PubXMLMonitor Lambda HANDLER provided by New-AWSPowerShellLambdaPackage during build 26 | 27 | ArtifactS3Bucket: 28 | Type: String 29 | Description: S3 Bucket for CodePipeline Artifacts 30 | 31 | ArtifactS3KeyPrefix: 32 | Type: String 33 | Description: S3 Key Prefix for CodePipeline Artifacts 34 | 35 | CodeBuildBadgeEnabled: 36 | Type: String 37 | Default: 'true' 38 | Description: Selects whether to enable CodeBuild Build Badges. 39 | AllowedValues: 40 | - 'true' 41 | - 'false' 42 | 43 | RepositoryUrl: 44 | Description: "HTTPS Clone URL of the repository in GitHub. Example: 'https://github.com/owner/repo.git'" 45 | Type: String 46 | Default: https://github.com/techthoughts2/PoshGram 47 | 48 | CodeBuildTimeoutInMinutes: 49 | Type: Number 50 | Default: 30 51 | Description: The number of minutes before a CodeBuild build will timeout. 52 | 53 | GitHubRepositoryName: 54 | Type: String 55 | Description: The name of the GitHub repository that code-pipeline will source from 56 | 57 | GitHubOwner: 58 | Type: String 59 | Description: The name of the GitHub user or organization who owns the GitHub repository. 60 | 61 | Resources: 62 | # Logical ID should be the same as the (child) nested template name - not required, but makes it easy to line things up and read 63 | 64 | # Deploys the CodePipeline infrastructure for CICD builds of PoshGram 65 | PoshGramMediaBuckets: 66 | Type: AWS::CloudFormation::Stack 67 | Properties: 68 | TemplateURL: ./childtemplates/buckets.yml 69 | TimeoutInMinutes: 25 #make sure it can actually complete in this time period 70 | Parameters: #much match the parameters of nested template 71 | ServiceName: !Ref ServiceName 72 | ResourceType: prod 73 | Tags: 74 | - Key: ServiceName 75 | Value: !Ref ServiceName 76 | - Key: StackName 77 | Value: !Ref AWS::StackName 78 | 79 | PoshGramCodeBuild: 80 | Type: AWS::CloudFormation::Stack 81 | DependsOn: PoshGramMediaBuckets 82 | Properties: 83 | TemplateURL: ./childtemplates/codebuild.yml 84 | TimeoutInMinutes: 15 #make sure it can actually complete in this time period 85 | Parameters: #much match the parameters of nested template 86 | ServiceName: !Ref ServiceName 87 | ResourceType: prod 88 | CodeBuildBadgeEnabled: !Ref CodeBuildBadgeEnabled 89 | RepositoryUrl: !Ref RepositoryUrl 90 | CodeBuildTimeoutInMinutes: !Ref CodeBuildTimeoutInMinutes 91 | Tags: 92 | - Key: ServiceName 93 | Value: !Ref ServiceName 94 | - Key: StackName 95 | Value: !Ref AWS::StackName 96 | 97 | # PoshGramCodePipeline: 98 | # Type: AWS::CloudFormation::Stack 99 | # DependsOn: PoshGramCodeBuild 100 | # Properties: 101 | # TemplateURL: ./childtemplates/codepipeline.yml 102 | # TimeoutInMinutes: 25 #make sure it can actually complete in this time period 103 | # Parameters: #much match the parameters of nested template 104 | # ServiceName: !Ref ServiceName 105 | # ResourceType: prod 106 | # GitHubRepositoryName: !Ref GitHubRepositoryName 107 | # GitHubOwner: !Ref GitHubOwner 108 | # Tags: 109 | # - Key: ServiceName 110 | # Value: !Ref ServiceName 111 | # - Key: StackName 112 | # Value: !Ref AWS::StackName 113 | -------------------------------------------------------------------------------- /configure_aws_credential.ps1: -------------------------------------------------------------------------------- 1 | <# 2 | .SYNOPSIS 3 | This script is used in AWS CodeBuild to configure the default AWS Credentials for use by the AWS CLI and the AWS Powershell module. 4 | .DESCRIPTION 5 | By default, the AWS PowerShell Module does not know about looking up an AWS Container's credentials path, so this works around that issue. 6 | .NOTES 7 | This script enables AWSPowerShell cmdlets in your CodeBuild to interact with and access other AWS resources in your account. 8 | #> 9 | 'Configuring AWS credentials' 10 | 11 | ' - Retrieving temporary credentials from metadata' 12 | $uri = 'http://169.254.170.2{0}' -f $env:AWS_CONTAINER_CREDENTIALS_RELATIVE_URI 13 | $sts = Invoke-RestMethod -UseBasicParsing -Uri $uri 14 | 15 | ' - Setting default AWS Credential' 16 | $credentialsFile = "$env:HOME\.aws\credentials" 17 | $null = New-Item -Path $credentialsFile -Force 18 | 19 | '[default]' | Out-File -FilePath $credentialsFile -Append 20 | 'aws_access_key_id={0}' -f $sts.AccessKeyId | Out-File -FilePath $credentialsFile -Append 21 | 'aws_secret_access_key={0}' -f $sts.SecretAccessKey | Out-File -FilePath $credentialsFile -Append 22 | 'aws_session_token={0}' -f $sts.Token | Out-File -FilePath $credentialsFile -Append 23 | 24 | ' - Setting default AWS Region' 25 | 'region={0}' -f $env:AWS_DEFAULT_REGION | Out-File -FilePath $credentialsFile -Append 26 | 27 | ' - AWS credentials configured' 28 | -------------------------------------------------------------------------------- /docs/Get-TelegramCustomEmojiStickerInfo.md: -------------------------------------------------------------------------------- 1 | --- 2 | external help file: PoshGram-help.xml 3 | Module Name: PoshGram 4 | online version: https://poshgram.readthedocs.io/en/latest/Get-TelegramCustomEmojiStickerInfo 5 | schema: 2.0.0 6 | --- 7 | 8 | # Get-TelegramCustomEmojiStickerInfo 9 | 10 | ## SYNOPSIS 11 | Retrieve information about Telegram custom emoji stickers using their identifiers. 12 | 13 | ## SYNTAX 14 | 15 | ``` 16 | Get-TelegramCustomEmojiStickerInfo [-BotToken] [-CustomEmojiIdentifier] 17 | [] 18 | ``` 19 | 20 | ## DESCRIPTION 21 | This function interacts with the Telegram Bot API to gather detailed information about custom emoji stickers 22 | specified by their unique identifiers. 23 | It can handle requests for up to 200 custom emoji IDs at a time 24 | 25 | ## EXAMPLES 26 | 27 | ### EXAMPLE 1 28 | ``` 29 | $botToken = 'nnnnnnnnn:xxxxxxx-xxxxxxxxxxxxxxxxxxxxxxxxxxx' 30 | Get-TelegramCustomEmojiStickerInfo -BotToken $botToken -CustomEmojiIdentifier 5404870433939922908 31 | ``` 32 | 33 | Retrieves detailed information about the custom emoji sticker with identifier 5404870433939922908. 34 | 35 | ### EXAMPLE 2 36 | ``` 37 | $botToken = 'nnnnnnnnn:xxxxxxx-xxxxxxxxxxxxxxxxxxxxxxxxxxx' 38 | Get-TelegramCustomEmojiStickerInfo -BotToken $botToken -CustomEmojiIdentifier 5404870433939922908, 5368324170671202286 39 | ``` 40 | 41 | Fetches information for multiple custom emoji stickers, using their respective identifiers 5404870433939922908 and 5368324170671202286. 42 | 43 | ## PARAMETERS 44 | 45 | ### -BotToken 46 | Use this token to access the HTTP API 47 | 48 | ```yaml 49 | Type: String 50 | Parameter Sets: (All) 51 | Aliases: 52 | 53 | Required: True 54 | Position: 1 55 | Default value: None 56 | Accept pipeline input: False 57 | Accept wildcard characters: False 58 | ``` 59 | 60 | ### -CustomEmojiIdentifier 61 | Custom emoji ID number(s). 62 | Specify up to 200 custom emoji IDs. 63 | 64 | ```yaml 65 | Type: String[] 66 | Parameter Sets: (All) 67 | Aliases: 68 | 69 | Required: True 70 | Position: 2 71 | Default value: None 72 | Accept pipeline input: False 73 | Accept wildcard characters: False 74 | ``` 75 | 76 | ### CommonParameters 77 | This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. 78 | For more information, see about_CommonParameters (http://go.microsoft.com/fwlink/?LinkID=113216). 79 | 80 | ## INPUTS 81 | 82 | ## OUTPUTS 83 | 84 | ### System.Management.Automation.PSCustomObject 85 | ## NOTES 86 | Author: Jake Morrison - @jakemorrison - https://www.techthoughts.info/ 87 | 88 | Questions on how to set up a bot, get a token, or get your channel ID? 89 | Answers on the PoshGram documentation: https://poshgram.readthedocs.io/en/latest/PoshGram-FAQ/ 90 | 91 | Note: 92 | - This function is currently experimental. 93 | Bots can only access custom emoji sticker information for purchased additional usernames on Fragment. 94 | - This makes it difficult to determine the custom emoji ID for a custom emoji sticker pack. 95 | - pwshEmojiExplorer is used to retrieve additional emoji information. 96 | 97 | ## RELATED LINKS 98 | 99 | [https://poshgram.readthedocs.io/en/latest/Get-TelegramCustomEmojiStickerInfo](https://poshgram.readthedocs.io/en/latest/Get-TelegramCustomEmojiStickerInfo) 100 | 101 | [https://poshgram.readthedocs.io/en/doctesting/PoshGram-Sticker-Info/](https://poshgram.readthedocs.io/en/doctesting/PoshGram-Sticker-Info/) 102 | 103 | [https://core.telegram.org/bots/api#getcustomemojistickers](https://core.telegram.org/bots/api#getcustomemojistickers) 104 | 105 | [https://core.telegram.org/bots/api#sticker](https://core.telegram.org/bots/api#sticker) 106 | 107 | [https://core.telegram.org/bots/api](https://core.telegram.org/bots/api) 108 | 109 | -------------------------------------------------------------------------------- /docs/Get-TelegramStickerPackInfo.md: -------------------------------------------------------------------------------- 1 | --- 2 | external help file: PoshGram-help.xml 3 | Module Name: PoshGram 4 | online version: https://poshgram.readthedocs.io/en/latest/Get-TelegramStickerPackInfo 5 | schema: 2.0.0 6 | --- 7 | 8 | # Get-TelegramStickerPackInfo 9 | 10 | ## SYNOPSIS 11 | Retrieve detailed information about a specified Telegram sticker pack. 12 | 13 | ## SYNTAX 14 | 15 | ``` 16 | Get-TelegramStickerPackInfo [-BotToken] [-StickerSetName] [] 17 | ``` 18 | 19 | ## DESCRIPTION 20 | This function connects to the Telegram Bot API to fetch detailed information about a specified sticker pack. 21 | It is designed to help you explore the contents of a Telegram sticker pack by providing a variety of information for each sticker. 22 | This includes details like the associated emoji, its group and subgroup classifications, Unicode code, shortcode, and the sticker's file ID. 23 | It also leverages the capabilities of pwshEmojiExplorer to retrieve additional emoji information, enriching the data set provided. 24 | To effectively use this function, you need the name of the sticker pack. 25 | You can find this by sharing the sticker pack within the Telegram app, which will generate a link containing the pack's name. 26 | More information is available in the links. 27 | 28 | ## EXAMPLES 29 | 30 | ### EXAMPLE 1 31 | ``` 32 | $botToken = 'nnnnnnnnn:xxxxxxx-xxxxxxxxxxxxxxxxxxxxxxxxxxx' 33 | Get-TelegramStickerPackInfo -BotToken $botToken -StickerSetName STPicard 34 | ``` 35 | 36 | Retrieves information for the STPicard sticker pack from the Telegram Bot API. 37 | 38 | ### EXAMPLE 2 39 | ``` 40 | $botToken = 'nnnnnnnnn:xxxxxxx-xxxxxxxxxxxxxxxxxxxxxxxxxxx' 41 | Get-TelegramStickerPackInfo -BotToken $botToken -StickerSetName FriendlyFelines 42 | ``` 43 | 44 | Retrieves information for the FriendlyFelines sticker pack from the Telegram Bot API. 45 | 46 | ## PARAMETERS 47 | 48 | ### -BotToken 49 | Use this token to access the HTTP API 50 | 51 | ```yaml 52 | Type: String 53 | Parameter Sets: (All) 54 | Aliases: 55 | 56 | Required: True 57 | Position: 1 58 | Default value: None 59 | Accept pipeline input: False 60 | Accept wildcard characters: False 61 | ``` 62 | 63 | ### -StickerSetName 64 | Name of the sticker set 65 | 66 | ```yaml 67 | Type: String 68 | Parameter Sets: (All) 69 | Aliases: 70 | 71 | Required: True 72 | Position: 2 73 | Default value: None 74 | Accept pipeline input: False 75 | Accept wildcard characters: False 76 | ``` 77 | 78 | ### CommonParameters 79 | This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. 80 | For more information, see about_CommonParameters (http://go.microsoft.com/fwlink/?LinkID=113216). 81 | 82 | ## INPUTS 83 | 84 | ## OUTPUTS 85 | 86 | ### System.Management.Automation.PSCustomObject 87 | ## NOTES 88 | Author: Jake Morrison - @jakemorrison - https://www.techthoughts.info/ 89 | 90 | Questions on how to set up a bot, get a token, or get your channel ID? 91 | Answers on the PoshGram documentation: https://poshgram.readthedocs.io/en/latest/PoshGram-FAQ/ 92 | 93 | Note: 94 | - Some sticker authors use the same emoji for several of their stickers. 95 | - pwshEmojiExplorer is used to retrieve additional emoji information. 96 | 97 | ## RELATED LINKS 98 | 99 | [https://poshgram.readthedocs.io/en/latest/Get-TelegramStickerPackInfo](https://poshgram.readthedocs.io/en/latest/Get-TelegramStickerPackInfo) 100 | 101 | [https://poshgram.readthedocs.io/en/doctesting/PoshGram-Sticker-Info/](https://poshgram.readthedocs.io/en/doctesting/PoshGram-Sticker-Info/) 102 | 103 | [https://core.telegram.org/bots/api#getstickerset](https://core.telegram.org/bots/api#getstickerset) 104 | 105 | [https://core.telegram.org/bots/api#sticker](https://core.telegram.org/bots/api#sticker) 106 | 107 | [https://core.telegram.org/bots/api](https://core.telegram.org/bots/api) 108 | 109 | -------------------------------------------------------------------------------- /docs/PoshGram-FAQ.md: -------------------------------------------------------------------------------- 1 | # PoshGram - FAQ 2 | 3 | ## FAQs 4 | 5 | ### I want to start using this, but how do I create a Telegram Bot and get a token? 6 | 7 | See [Setting Up Telegram Bot](PoshGram-Telegram-API.md). 8 | 9 | ### How do I determine what Chat ID my bot is a part of? 10 | 11 | See [How do I determine my chat ID number?](PoshGram-Telegram-API.md#how-do-i-determine-my-chat-id-number) 12 | 13 | ### How can I use PoshGram to have my bot send stickers? 14 | 15 | See [PoshGram-Sticker-Info](PoshGram-Sticker-Info.md). 16 | 17 | ### How can I properly engage formatting text in messages? 18 | 19 | - See [Message Formatting](PoshGram-Basics.md#formatting) for examples on how to use HTML and Markdown formatting in your messages. 20 | - See [Escaping Characters](PoshGram-Advanced.md#escaping-characters) to properly escape characters in your messages. 21 | 22 | ### How can I use PoshGram to send inline Emojis? 23 | 24 | See [Sending emojis](PoshGram-Advanced.md#sending-emojis). 25 | 26 | ### How can I send properly formed keyboards? 27 | 28 | See [Sending keyboards](PoshGram-Advanced.md#keyboards). 29 | 30 | ### Why does PoshGram only support higher versions of PowerShell? 31 | 32 | - *Why is PowerShell 6.1.0 (or higher) required? - Why can't I use 5.1?* 33 | - For new files to be uploaded and sent to a chat via bot, Telegram requires the use of multipart/form-data. This is not natively supported in 5.1. It is available in 6.0.0, but requires the manual creation of the form. 6.1.0 introduces native form capabilities. Functions that reference a URL, or that only use messaging (**Send-TelegramTextMessage**) are 5.1 compatible. However, you would have to pull these functions out separately if you are absolutely set on using 5.1 34 | 35 | - *I don't want to use PowerShell 6.1.0 (or higher) because I primarily use 5.1 or lower* 36 | - Good news - PowerShell 6.1.0+ installs to a completely separate folder, has a completely different exe (`pwsh.exe`), and references a different module path. This means you can install it on any system and use PoshGram while continuing to use any other version of PowerShell 37 | - Here are some examples of how you can call PS 6.1 and use PoshGram from older versions of PowerShell: 38 | 39 | ```powershell 40 | #here is an example of calling PowerShell 6.1+ from PowerShell 5.1 to send a Telegram message with PoshGram using dynamic variables in the message 41 | $botToken = “#########:xxxxxxx-xxxxxxxxxxxxxxxxxxxxxxxxxxx” 42 | $chatID = “-#########” 43 | $test = "I am a test" 44 | & '.\Program Files\PowerShell\6\pwsh.exe' -command "& {Import-Module PoshGram;Send-TelegramTextMessage -BotToken $botToken -ChatID $chatID -Message '$test';}" 45 | #-------------------------------------------------------------------------- 46 | #here is an example of calling PowerShell 7+ from PowerShell 5.1 to send a Telegram message with PoshGram 47 | & 'C:\Program Files\PowerShell\7\pwsh.exe' -command { Import-Module PoshGram;$botToken = '#########:xxxxxxx-xxxxxxxxxxxxxxxxxxxxxxxxxxx';$chatID = '-nnnnnnnnn';Send-TelegramTextMessage -BotToken $botToken -ChatID $chatID -Message "Test from 5.1 calling 7+ to send Telegram Message via PoshGram" } 48 | ``` 49 | 50 | ### Are there any restrictions when using PoshGram? 51 | 52 | - Bots can currently send files of up to 50 MB in size 53 | - Certain functions are limited to certain file extensions, see each function's documentation for more information 54 | -------------------------------------------------------------------------------- /docs/PoshGram-Telegram-API.md: -------------------------------------------------------------------------------- 1 | # Setting Up Telegram Bot 2 | 3 | PoshGram requires that you create a Bot and get its Bot ID token. You will also need to add your bot to a group or channel and retrieve the chat ID of that group. 4 | 5 | ## How to get a Telegram Bot API Key 6 | 7 | Just message the [BotFather](https://t.me/BotFather) and follow the directions. 8 | 9 | If you want more resources here are some links and a video guide below. 10 | 11 | - To learn how to create and set up a bot: 12 | - Official Telegram Documentation 13 | - [How Do I Create a Bot?](https://core.telegram.org/bots#how-do-i-create-a-bot) 14 | - [Bot FAQ](https://core.telegram.org/bots/faq) 15 | - [Introduction to Bots](https://core.telegram.org/bots) 16 | - [TechThoughts video on how to make a Telegram Bot](https://youtu.be/UhZtrhV7t3U) 17 | 18 | ## How do I determine my chat ID number? 19 | 20 | *I've got a bot setup, and I have a token, but how do I determine my chat ID number (also referred to as the channel ID)?* 21 | 22 | ### Preferred Method - Web Client 23 | 24 | The easiest way is to login to the [Telegram Web Client](https://web.telegram.org/#/login) and find your channel on the left. When you select it the address in your URL bar will change. 25 | 26 | 1. Go to [https://web.telegram.org](https://web.telegram.org/#/login) 27 | 2. Click on your channel 28 | 3. Look at the url, and copy the channel ID in your browser's address bar 29 | - It may look something like the below examples: 30 | - `#/im?p=g112345678` 31 | - `#-828938028` 32 | - *Just copy the ending numbers with no characters or symbols.* 33 | 4. Add a `-` to the front of your numbers to and this is your Chat ID number. 34 | - Ex `-#########` 35 | - Ex from above would be: `-112345678` 36 | 37 | ### Message Method 38 | 39 | Send your bot a message and then retrieve your bot's `getUpdates` which contains your chat ID. 40 | 41 | 1. Go to your channel 42 | 2. Message your bot. *Note: your bot needs to be a member of the channel for this method to work* 43 | - In this example I message the `@poshgram_bot` 44 | - `/my_id @yourbot_bot` 45 | 3. Retrieve the `getUpdates` for your bot using its token 46 | 47 | ```powershell 48 | $botToken = 'nnnnnnnnn:xxxxxxx-xxxxxxxxxxxxxxxxxxxxxxxxxxx' 49 | $Updates = Invoke-WebRequest -Uri "https://api.telegram.org/bot$botToken/getUpdates" 50 | $objUpdates = ConvertFrom-Json $Updates.Content 51 | $objUpdates.result.message.chat.id 52 | ``` 53 | -------------------------------------------------------------------------------- /docs/PoshGram.md: -------------------------------------------------------------------------------- 1 | --- 2 | Module Name: PoshGram 3 | Module Guid: 277b92bc-0ea9-4659-8f6c-ed5a1dfdfda2 4 | Download Help Link: NA 5 | Help Version: 3.0.1 6 | Locale: en-US 7 | --- 8 | 9 | # PoshGram Module 10 | ## Description 11 | PoshGram provides functionality to send various message types to a specified Telegram chat via the Telegram Bot API. Separate PowerShell functions are used for each message type. Checks are included to ensure that file extensions, and file size restrictions are adhered to based on Telegram requirements. 12 | 13 | ## PoshGram Cmdlets 14 | ### [Get-TelegramCustomEmojiStickerInfo](Get-TelegramCustomEmojiStickerInfo.md) 15 | Retrieve information about Telegram custom emoji stickers using their identifiers. 16 | 17 | ### [Get-TelegramStickerPackInfo](Get-TelegramStickerPackInfo.md) 18 | Retrieve detailed information about a specified Telegram sticker pack. 19 | 20 | ### [Send-TelegramContact](Send-TelegramContact.md) 21 | Sends Telegram phone contact message via BOT API. 22 | 23 | ### [Send-TelegramDice](Send-TelegramDice.md) 24 | Sends Telegram animated emoji that will display a random value. 25 | 26 | ### [Send-TelegramLocalAnimation](Send-TelegramLocalAnimation.md) 27 | Sends Telegram animation message via Bot API from locally sourced animation 28 | 29 | ### [Send-TelegramLocalAudio](Send-TelegramLocalAudio.md) 30 | Sends Telegram audio message via Bot API from locally sourced file 31 | 32 | ### [Send-TelegramLocalDocument](Send-TelegramLocalDocument.md) 33 | Sends Telegram document message via Bot API from locally sourced file 34 | 35 | ### [Send-TelegramLocalPhoto](Send-TelegramLocalPhoto.md) 36 | Sends Telegram photo message via Bot API from locally sourced photo image 37 | 38 | ### [Send-TelegramLocalSticker](Send-TelegramLocalSticker.md) 39 | Sends Telegram sticker message via Bot API from locally sourced sticker image 40 | 41 | ### [Send-TelegramLocalVideo](Send-TelegramLocalVideo.md) 42 | Sends Telegram video message via Bot API from locally sourced file 43 | 44 | ### [Send-TelegramLocation](Send-TelegramLocation.md) 45 | Sends Telegram location to indicate point on map 46 | 47 | ### [Send-TelegramMediaGroup](Send-TelegramMediaGroup.md) 48 | Sends Telegram a group of photos, videos, documents, or audios as an album via Bot API from locally sourced media 49 | 50 | ### [Send-TelegramPoll](Send-TelegramPoll.md) 51 | Sends Telegram native poll. 52 | 53 | ### [Send-TelegramSticker](Send-TelegramSticker.md) 54 | Sends Telegram sticker message via Bot API by file_id or sticker pack emoji. 55 | 56 | ### [Send-TelegramTextMessage](Send-TelegramTextMessage.md) 57 | Send a text message via Telegram Bot API. 58 | 59 | ### [Send-TelegramURLAnimation](Send-TelegramURLAnimation.md) 60 | Sends Telegram animation message via Bot API from URL sourced animation image 61 | 62 | ### [Send-TelegramURLAudio](Send-TelegramURLAudio.md) 63 | Sends Telegram audio message via Bot API from URL sourced file 64 | 65 | ### [Send-TelegramURLDocument](Send-TelegramURLDocument.md) 66 | Sends Telegram document message via Bot API from URL sourced file 67 | 68 | ### [Send-TelegramURLPhoto](Send-TelegramURLPhoto.md) 69 | Sends Telegram photo message via Bot API from URL sourced photo image 70 | 71 | ### [Send-TelegramURLSticker](Send-TelegramURLSticker.md) 72 | Sends Telegram sticker message via Bot API from URL sourced sticker image 73 | 74 | ### [Send-TelegramURLVideo](Send-TelegramURLVideo.md) 75 | Sends Telegram video message via Bot API from URL sourced file 76 | 77 | ### [Send-TelegramVenue](Send-TelegramVenue.md) 78 | Sends Telegram information about a venue. 79 | 80 | ### [Test-BotToken](Test-BotToken.md) 81 | Validates Bot auth Token 82 | 83 | 84 | -------------------------------------------------------------------------------- /docs/Send-TelegramContact.md: -------------------------------------------------------------------------------- 1 | --- 2 | external help file: PoshGram-help.xml 3 | Module Name: PoshGram 4 | online version: https://poshgram.readthedocs.io/en/latest/Send-TelegramContact 5 | schema: 2.0.0 6 | --- 7 | 8 | # Send-TelegramContact 9 | 10 | ## SYNOPSIS 11 | Sends Telegram phone contact message via BOT API. 12 | 13 | ## SYNTAX 14 | 15 | ``` 16 | Send-TelegramContact [-BotToken] [-ChatID] [-PhoneNumber] [-FirstName] 17 | [[-LastName] ] [-DisableNotification] [-ProtectContent] [] 18 | ``` 19 | 20 | ## DESCRIPTION 21 | Uses Telegram Bot API to send contact information to specified Telegram chat. 22 | 23 | ## EXAMPLES 24 | 25 | ### EXAMPLE 1 26 | ``` 27 | $botToken = 'nnnnnnnnn:xxxxxxx-xxxxxxxxxxxxxxxxxxxxxxxxxxx' 28 | $chatID = '-nnnnnnnnn' 29 | $phone = '1-222-222-2222' 30 | $firstName = 'Jean-Luc' 31 | Send-TelegramContact -BotToken $botToken -ChatID $chatID -PhoneNumber $phone -FirstName $firstName 32 | ``` 33 | 34 | Sends contact via Telegram API 35 | 36 | ### EXAMPLE 2 37 | ``` 38 | $botToken = 'nnnnnnnnn:xxxxxxx-xxxxxxxxxxxxxxxxxxxxxxxxxxx' 39 | $chatID = '-nnnnnnnnn' 40 | $phone = '1-222-222-2222' 41 | $firstName = 'Jean-Luc' 42 | $lastName = 'Picard' 43 | $sendTelegramContactSplat = @{ 44 | BotToken = $botToken 45 | ChatID = $chatID 46 | PhoneNumber = $phone 47 | FirstName = $firstName 48 | LastName = $lastName 49 | DisableNotification = $true 50 | ProtectContent = $true 51 | Verbose = $true 52 | } 53 | Send-TelegramContact @sendTelegramContactSplat 54 | ``` 55 | 56 | Sends contact via Telegram API 57 | 58 | ## PARAMETERS 59 | 60 | ### -BotToken 61 | Use this token to access the HTTP API 62 | 63 | ```yaml 64 | Type: String 65 | Parameter Sets: (All) 66 | Aliases: 67 | 68 | Required: True 69 | Position: 1 70 | Default value: None 71 | Accept pipeline input: False 72 | Accept wildcard characters: False 73 | ``` 74 | 75 | ### -ChatID 76 | Unique identifier for the target chat 77 | 78 | ```yaml 79 | Type: String 80 | Parameter Sets: (All) 81 | Aliases: 82 | 83 | Required: True 84 | Position: 2 85 | Default value: None 86 | Accept pipeline input: False 87 | Accept wildcard characters: False 88 | ``` 89 | 90 | ### -PhoneNumber 91 | Contact phone number 92 | 93 | ```yaml 94 | Type: String 95 | Parameter Sets: (All) 96 | Aliases: 97 | 98 | Required: True 99 | Position: 3 100 | Default value: None 101 | Accept pipeline input: False 102 | Accept wildcard characters: False 103 | ``` 104 | 105 | ### -FirstName 106 | Contact first name 107 | 108 | ```yaml 109 | Type: String 110 | Parameter Sets: (All) 111 | Aliases: 112 | 113 | Required: True 114 | Position: 4 115 | Default value: None 116 | Accept pipeline input: False 117 | Accept wildcard characters: False 118 | ``` 119 | 120 | ### -LastName 121 | Contact last name 122 | 123 | ```yaml 124 | Type: String 125 | Parameter Sets: (All) 126 | Aliases: 127 | 128 | Required: False 129 | Position: 5 130 | Default value: None 131 | Accept pipeline input: False 132 | Accept wildcard characters: False 133 | ``` 134 | 135 | ### -DisableNotification 136 | Send the message silently. 137 | Users will receive a notification with no sound. 138 | 139 | ```yaml 140 | Type: SwitchParameter 141 | Parameter Sets: (All) 142 | Aliases: 143 | 144 | Required: False 145 | Position: Named 146 | Default value: False 147 | Accept pipeline input: False 148 | Accept wildcard characters: False 149 | ``` 150 | 151 | ### -ProtectContent 152 | Protects the contents of the sent message from forwarding and saving 153 | 154 | ```yaml 155 | Type: SwitchParameter 156 | Parameter Sets: (All) 157 | Aliases: 158 | 159 | Required: False 160 | Position: Named 161 | Default value: False 162 | Accept pipeline input: False 163 | Accept wildcard characters: False 164 | ``` 165 | 166 | ### CommonParameters 167 | This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. 168 | For more information, see about_CommonParameters (http://go.microsoft.com/fwlink/?LinkID=113216). 169 | 170 | ## INPUTS 171 | 172 | ## OUTPUTS 173 | 174 | ### System.Management.Automation.PSCustomObject 175 | ## NOTES 176 | Author: Jake Morrison - @jakemorrison - https://www.techthoughts.info/ 177 | 178 | Questions on how to set up a bot, get a token, or get your channel ID? 179 | Answers on the PoshGram documentation: https://poshgram.readthedocs.io/en/latest/PoshGram-FAQ/ 180 | 181 | ## RELATED LINKS 182 | 183 | [https://poshgram.readthedocs.io/en/latest/Send-TelegramContact](https://poshgram.readthedocs.io/en/latest/Send-TelegramContact) 184 | 185 | [https://core.telegram.org/bots/api#sendcontact](https://core.telegram.org/bots/api#sendcontact) 186 | 187 | [https://core.telegram.org/bots/api](https://core.telegram.org/bots/api) 188 | 189 | -------------------------------------------------------------------------------- /docs/Send-TelegramDice.md: -------------------------------------------------------------------------------- 1 | --- 2 | external help file: PoshGram-help.xml 3 | Module Name: PoshGram 4 | online version: https://poshgram.readthedocs.io/en/latest/Send-TelegramDice 5 | schema: 2.0.0 6 | --- 7 | 8 | # Send-TelegramDice 9 | 10 | ## SYNOPSIS 11 | Sends Telegram animated emoji that will display a random value. 12 | 13 | ## SYNTAX 14 | 15 | ``` 16 | Send-TelegramDice [-BotToken] [-ChatID] [-Emoji] [-DisableNotification] 17 | [-ProtectContent] [] 18 | ``` 19 | 20 | ## DESCRIPTION 21 | Uses Telegram Bot API to send animated emoji that will display a random value to specified Telegram chat. 22 | 23 | ## EXAMPLES 24 | 25 | ### EXAMPLE 1 26 | ``` 27 | $botToken = 'nnnnnnnnn:xxxxxxx-xxxxxxxxxxxxxxxxxxxxxxxxxxx' 28 | $chatID = '-nnnnnnnnn' 29 | $emoji = 'basketball' 30 | Send-TelegramDice -BotToken $botToken -ChatID $chatID -Emoji $emoji 31 | ``` 32 | 33 | Sends animated basketball emoji that displays a random value via Telegram API 34 | 35 | ### EXAMPLE 2 36 | ``` 37 | $botToken = 'nnnnnnnnn:xxxxxxx-xxxxxxxxxxxxxxxxxxxxxxxxxxx' 38 | $chatID = '-nnnnnnnnn' 39 | $emoji = 'dice' 40 | $sendTelegramDiceSplat = @{ 41 | BotToken = $botToken 42 | ChatID = $chatID 43 | DisableNotification = $true 44 | ProtectContent = $true 45 | Verbose = $true 46 | Emoji = $emoji 47 | } 48 | Send-TelegramDice @sendTelegramDiceSplat 49 | ``` 50 | 51 | Sends animated dice emoji that displays a random value via Telegram API 52 | 53 | ## PARAMETERS 54 | 55 | ### -BotToken 56 | Use this token to access the HTTP API 57 | 58 | ```yaml 59 | Type: String 60 | Parameter Sets: (All) 61 | Aliases: 62 | 63 | Required: True 64 | Position: 1 65 | Default value: None 66 | Accept pipeline input: False 67 | Accept wildcard characters: False 68 | ``` 69 | 70 | ### -ChatID 71 | Unique identifier for the target chat 72 | 73 | ```yaml 74 | Type: String 75 | Parameter Sets: (All) 76 | Aliases: 77 | 78 | Required: True 79 | Position: 2 80 | Default value: None 81 | Accept pipeline input: False 82 | Accept wildcard characters: False 83 | ``` 84 | 85 | ### -Emoji 86 | Emoji on which the dice throw animation is based. 87 | 88 | ```yaml 89 | Type: String 90 | Parameter Sets: (All) 91 | Aliases: 92 | 93 | Required: True 94 | Position: 3 95 | Default value: None 96 | Accept pipeline input: False 97 | Accept wildcard characters: False 98 | ``` 99 | 100 | ### -DisableNotification 101 | Send the message silently. 102 | Users will receive a notification with no sound. 103 | 104 | ```yaml 105 | Type: SwitchParameter 106 | Parameter Sets: (All) 107 | Aliases: 108 | 109 | Required: False 110 | Position: Named 111 | Default value: False 112 | Accept pipeline input: False 113 | Accept wildcard characters: False 114 | ``` 115 | 116 | ### -ProtectContent 117 | Protects the contents of the sent message from forwarding and saving 118 | 119 | ```yaml 120 | Type: SwitchParameter 121 | Parameter Sets: (All) 122 | Aliases: 123 | 124 | Required: False 125 | Position: Named 126 | Default value: False 127 | Accept pipeline input: False 128 | Accept wildcard characters: False 129 | ``` 130 | 131 | ### CommonParameters 132 | This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. 133 | For more information, see about_CommonParameters (http://go.microsoft.com/fwlink/?LinkID=113216). 134 | 135 | ## INPUTS 136 | 137 | ## OUTPUTS 138 | 139 | ### System.Management.Automation.PSCustomObject 140 | ## NOTES 141 | Author: Jake Morrison - @jakemorrison - https://www.techthoughts.info/ 142 | 143 | Questions on how to set up a bot, get a token, or get your channel ID? 144 | Answers on the PoshGram documentation: https://poshgram.readthedocs.io/en/latest/PoshGram-FAQ/ 145 | 146 | ## RELATED LINKS 147 | 148 | [https://poshgram.readthedocs.io/en/latest/Send-TelegramDice](https://poshgram.readthedocs.io/en/latest/Send-TelegramDice) 149 | 150 | [https://core.telegram.org/bots/api#senddice](https://core.telegram.org/bots/api#senddice) 151 | 152 | [https://core.telegram.org/bots/api](https://core.telegram.org/bots/api) 153 | 154 | -------------------------------------------------------------------------------- /docs/Send-TelegramLocalSticker.md: -------------------------------------------------------------------------------- 1 | --- 2 | external help file: PoshGram-help.xml 3 | Module Name: PoshGram 4 | online version: https://poshgram.readthedocs.io/en/latest/Send-TelegramLocalSticker 5 | schema: 2.0.0 6 | --- 7 | 8 | # Send-TelegramLocalSticker 9 | 10 | ## SYNOPSIS 11 | Sends Telegram sticker message via Bot API from locally sourced sticker image 12 | 13 | ## SYNTAX 14 | 15 | ``` 16 | Send-TelegramLocalSticker [-BotToken] [-ChatID] [-StickerPath] [[-Emoji] ] 17 | [-DisableNotification] [-ProtectContent] [] 18 | ``` 19 | 20 | ## DESCRIPTION 21 | Uses Telegram Bot API to send sticker message to specified Telegram chat. 22 | The sticker will be sourced from the local device and uploaded to telegram. 23 | 24 | ## EXAMPLES 25 | 26 | ### EXAMPLE 1 27 | ``` 28 | $botToken = 'nnnnnnnnn:xxxxxxx-xxxxxxxxxxxxxxxxxxxxxxxxxxx' 29 | $chatID = '-nnnnnnnnn' 30 | $sticker = 'C:\stickers\sticker.webp' 31 | Send-TelegramLocalSticker -BotToken $botToken -ChatID $chatID -StickerPath $sticker 32 | ``` 33 | 34 | Sends sticker message via Telegram API 35 | 36 | ### EXAMPLE 2 37 | ``` 38 | $botToken = 'nnnnnnnnn:xxxxxxx-xxxxxxxxxxxxxxxxxxxxxxxxxxx' 39 | $chatID = '-nnnnnnnnn' 40 | $sticker = 'C:\stickers\sticker.webp' 41 | $sendTelegramLocalStickerSplat = @{ 42 | BotToken = $botToken 43 | ChatID = $chatID 44 | StickerPath = $sticker 45 | Emoji = '😀' 46 | DisableNotification = $true 47 | ProtectContent = $true 48 | Verbose = $true 49 | } 50 | Send-TelegramLocalSticker @sendTelegramLocalStickerSplat 51 | ``` 52 | 53 | Sends sticker message via Telegram API 54 | 55 | ## PARAMETERS 56 | 57 | ### -BotToken 58 | Use this token to access the HTTP API 59 | 60 | ```yaml 61 | Type: String 62 | Parameter Sets: (All) 63 | Aliases: 64 | 65 | Required: True 66 | Position: 1 67 | Default value: None 68 | Accept pipeline input: False 69 | Accept wildcard characters: False 70 | ``` 71 | 72 | ### -ChatID 73 | Unique identifier for the target chat 74 | 75 | ```yaml 76 | Type: String 77 | Parameter Sets: (All) 78 | Aliases: 79 | 80 | Required: True 81 | Position: 2 82 | Default value: None 83 | Accept pipeline input: False 84 | Accept wildcard characters: False 85 | ``` 86 | 87 | ### -StickerPath 88 | File path to the sticker you wish to send 89 | 90 | ```yaml 91 | Type: String 92 | Parameter Sets: (All) 93 | Aliases: 94 | 95 | Required: True 96 | Position: 3 97 | Default value: None 98 | Accept pipeline input: False 99 | Accept wildcard characters: False 100 | ``` 101 | 102 | ### -Emoji 103 | Emoji associated with the sticker 104 | 105 | ```yaml 106 | Type: String 107 | Parameter Sets: (All) 108 | Aliases: 109 | 110 | Required: False 111 | Position: 4 112 | Default value: None 113 | Accept pipeline input: False 114 | Accept wildcard characters: False 115 | ``` 116 | 117 | ### -DisableNotification 118 | Send the message silently. 119 | Users will receive a notification with no sound. 120 | 121 | ```yaml 122 | Type: SwitchParameter 123 | Parameter Sets: (All) 124 | Aliases: 125 | 126 | Required: False 127 | Position: Named 128 | Default value: False 129 | Accept pipeline input: False 130 | Accept wildcard characters: False 131 | ``` 132 | 133 | ### -ProtectContent 134 | Protects the contents of the sent message from forwarding and saving 135 | 136 | ```yaml 137 | Type: SwitchParameter 138 | Parameter Sets: (All) 139 | Aliases: 140 | 141 | Required: False 142 | Position: Named 143 | Default value: False 144 | Accept pipeline input: False 145 | Accept wildcard characters: False 146 | ``` 147 | 148 | ### CommonParameters 149 | This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. 150 | For more information, see about_CommonParameters (http://go.microsoft.com/fwlink/?LinkID=113216). 151 | 152 | ## INPUTS 153 | 154 | ## OUTPUTS 155 | 156 | ### System.Management.Automation.PSCustomObject 157 | ## NOTES 158 | Author: Jake Morrison - @jakemorrison - https://www.techthoughts.info/ 159 | 160 | The following sticker types are supported: 161 | WEBP, TGS, WEBM 162 | 163 | Questions on how to set up a bot, get a token, or get your channel ID? 164 | Answers on the PoshGram documentation: https://poshgram.readthedocs.io/en/latest/PoshGram-FAQ/ 165 | 166 | ## RELATED LINKS 167 | 168 | [https://poshgram.readthedocs.io/en/latest/Send-TelegramLocalSticker](https://poshgram.readthedocs.io/en/latest/Send-TelegramLocalSticker) 169 | 170 | [https://core.telegram.org/bots/api#sendsticker](https://core.telegram.org/bots/api#sendsticker) 171 | 172 | [https://core.telegram.org/bots/api](https://core.telegram.org/bots/api) 173 | 174 | -------------------------------------------------------------------------------- /docs/Send-TelegramLocation.md: -------------------------------------------------------------------------------- 1 | --- 2 | external help file: PoshGram-help.xml 3 | Module Name: PoshGram 4 | online version: https://poshgram.readthedocs.io/en/latest/Send-TelegramLocation 5 | schema: 2.0.0 6 | --- 7 | 8 | # Send-TelegramLocation 9 | 10 | ## SYNOPSIS 11 | Sends Telegram location to indicate point on map 12 | 13 | ## SYNTAX 14 | 15 | ``` 16 | Send-TelegramLocation [-BotToken] [-ChatID] [-Latitude] [-Longitude] 17 | [-DisableNotification] [-ProtectContent] [] 18 | ``` 19 | 20 | ## DESCRIPTION 21 | Uses Telegram Bot API to send latitude and longitude points on map to specified Telegram chat. 22 | 23 | ## EXAMPLES 24 | 25 | ### EXAMPLE 1 26 | ``` 27 | $botToken = 'nnnnnnnnn:xxxxxxx-xxxxxxxxxxxxxxxxxxxxxxxxxxx' 28 | $chatID = '-nnnnnnnnn' 29 | $latitude = 37.621313 30 | $longitude = -122.378955 31 | Send-TelegramLocation -BotToken $botToken -ChatID $chatID -Latitude $latitude -Longitude $longitude 32 | ``` 33 | 34 | Sends location via Telegram API 35 | 36 | ### EXAMPLE 2 37 | ``` 38 | $botToken = 'nnnnnnnnn:xxxxxxx-xxxxxxxxxxxxxxxxxxxxxxxxxxx' 39 | $chatID = '-nnnnnnnnn' 40 | $sendTelegramLocationSplat = @{ 41 | BotToken = $botToken 42 | ChatID = $chatID 43 | Latitude = $latitude 44 | Longitude = $longitude 45 | DisableNotification = $true 46 | ProtectContent = $true 47 | Verbose = $true 48 | } 49 | Send-TelegramLocation @sendTelegramLocationSplat 50 | ``` 51 | 52 | Sends location via Telegram API 53 | 54 | ## PARAMETERS 55 | 56 | ### -BotToken 57 | Use this token to access the HTTP API 58 | 59 | ```yaml 60 | Type: String 61 | Parameter Sets: (All) 62 | Aliases: 63 | 64 | Required: True 65 | Position: 1 66 | Default value: None 67 | Accept pipeline input: False 68 | Accept wildcard characters: False 69 | ``` 70 | 71 | ### -ChatID 72 | Unique identifier for the target chat 73 | 74 | ```yaml 75 | Type: String 76 | Parameter Sets: (All) 77 | Aliases: 78 | 79 | Required: True 80 | Position: 2 81 | Default value: None 82 | Accept pipeline input: False 83 | Accept wildcard characters: False 84 | ``` 85 | 86 | ### -Latitude 87 | Latitude of the location 88 | 89 | ```yaml 90 | Type: Single 91 | Parameter Sets: (All) 92 | Aliases: 93 | 94 | Required: True 95 | Position: 3 96 | Default value: 0 97 | Accept pipeline input: False 98 | Accept wildcard characters: False 99 | ``` 100 | 101 | ### -Longitude 102 | Longitude of the location 103 | 104 | ```yaml 105 | Type: Single 106 | Parameter Sets: (All) 107 | Aliases: 108 | 109 | Required: True 110 | Position: 4 111 | Default value: 0 112 | Accept pipeline input: False 113 | Accept wildcard characters: False 114 | ``` 115 | 116 | ### -DisableNotification 117 | Send the message silently. 118 | Users will receive a notification with no sound. 119 | 120 | ```yaml 121 | Type: SwitchParameter 122 | Parameter Sets: (All) 123 | Aliases: 124 | 125 | Required: False 126 | Position: Named 127 | Default value: False 128 | Accept pipeline input: False 129 | Accept wildcard characters: False 130 | ``` 131 | 132 | ### -ProtectContent 133 | Protects the contents of the sent message from forwarding and saving 134 | 135 | ```yaml 136 | Type: SwitchParameter 137 | Parameter Sets: (All) 138 | Aliases: 139 | 140 | Required: False 141 | Position: Named 142 | Default value: False 143 | Accept pipeline input: False 144 | Accept wildcard characters: False 145 | ``` 146 | 147 | ### CommonParameters 148 | This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. 149 | For more information, see about_CommonParameters (http://go.microsoft.com/fwlink/?LinkID=113216). 150 | 151 | ## INPUTS 152 | 153 | ## OUTPUTS 154 | 155 | ### System.Management.Automation.PSCustomObject 156 | ## NOTES 157 | Author: Jake Morrison - @jakemorrison - https://www.techthoughts.info/ 158 | 159 | Questions on how to set up a bot, get a token, or get your channel ID? 160 | Answers on the PoshGram documentation: https://poshgram.readthedocs.io/en/latest/PoshGram-FAQ/ 161 | 162 | ## RELATED LINKS 163 | 164 | [https://poshgram.readthedocs.io/en/latest/Send-TelegramLocation](https://poshgram.readthedocs.io/en/latest/Send-TelegramLocation) 165 | 166 | [https://core.telegram.org/bots/api#sendlocation](https://core.telegram.org/bots/api#sendlocation) 167 | 168 | [https://core.telegram.org/bots/api](https://core.telegram.org/bots/api) 169 | 170 | -------------------------------------------------------------------------------- /docs/Send-TelegramMediaGroup.md: -------------------------------------------------------------------------------- 1 | --- 2 | external help file: PoshGram-help.xml 3 | Module Name: PoshGram 4 | online version: https://poshgram.readthedocs.io/en/latest/Send-TelegramMediaGroup 5 | schema: 2.0.0 6 | --- 7 | 8 | # Send-TelegramMediaGroup 9 | 10 | ## SYNOPSIS 11 | Sends Telegram a group of photos, videos, documents, or audios as an album via Bot API from locally sourced media 12 | 13 | ## SYNTAX 14 | 15 | ``` 16 | Send-TelegramMediaGroup [-BotToken] [-ChatID] [-MediaType] [[-FilePaths] ] 17 | [-DisableNotification] [-ProtectContent] [] 18 | ``` 19 | 20 | ## DESCRIPTION 21 | Uses Telegram Bot API to send a group of photos, videos, documents, or audios as an album message to specified Telegram chat. 22 | The media will be sourced from the local device and uploaded to telegram. 23 | This function only supports sending one media type per send (Photo | Video | Documents | Audio). 24 | 2 files minimum and 10 files maximum are required for this function. 25 | 26 | ## EXAMPLES 27 | 28 | ### EXAMPLE 1 29 | ``` 30 | $botToken = 'nnnnnnnnn:xxxxxxx-xxxxxxxxxxxxxxxxxxxxxxxxxxx' 31 | $chatID = '-nnnnnnnnn' 32 | $sendTelegramMediaGroupSplat = @{ 33 | BotToken = $botToken 34 | ChatID = $chatID 35 | MediaType = 'Photo' 36 | FilePaths = 'C:\photo\photo1.jpg', 'C:\photo\photo2.jpg' 37 | } 38 | Send-TelegramMediaGroup @sendTelegramMediaGroupSplat 39 | ``` 40 | 41 | Uploads all provided photo files as album via Telegram Bot API. 42 | 43 | ### EXAMPLE 2 44 | ``` 45 | $botToken = 'nnnnnnnnn:xxxxxxx-xxxxxxxxxxxxxxxxxxxxxxxxxxx' 46 | $chatID = '-nnnnnnnnn' 47 | $sendTelegramMediaGroupSplat = @{ 48 | BotToken = $botToken 49 | ChatID = $chatID 50 | MediaType = 'Photo' 51 | FilePaths = (Get-ChildItem C:\PhotoGroup | Select-Object -ExpandProperty FullName) 52 | } 53 | Send-TelegramMediaGroup @sendTelegramMediaGroupSplat 54 | ``` 55 | 56 | Retrieves all photo file paths from C:\PhotoGroup and uploads as photo album. 57 | Keep in mind that your location must have at least 2, but not more than 10 files. 58 | 59 | ### EXAMPLE 3 60 | ``` 61 | $botToken = 'nnnnnnnnn:xxxxxxx-xxxxxxxxxxxxxxxxxxxxxxxxxxx' 62 | $chatID = '-nnnnnnnnn' 63 | $vPath = 'C:\VideoGroup' 64 | $vFiles = @( 65 | "$vPath\first_contact.mp4", 66 | "$vPath\root_beer.mp4" 67 | ) 68 | $sendTelegramMediaGroupSplat = @{ 69 | BotToken = $botToken 70 | ChatID = $chatID 71 | MediaType = 'Video' 72 | FilePaths = $vFiles 73 | DisableNotification = $true 74 | ProtectContent = $true 75 | } 76 | Send-TelegramMediaGroup @sendTelegramMediaGroupSplat 77 | ``` 78 | 79 | Uploads all provided video files as album via Telegram Bot API. 80 | 81 | ## PARAMETERS 82 | 83 | ### -BotToken 84 | Use this token to access the HTTP API 85 | 86 | ```yaml 87 | Type: String 88 | Parameter Sets: (All) 89 | Aliases: 90 | 91 | Required: True 92 | Position: 1 93 | Default value: None 94 | Accept pipeline input: False 95 | Accept wildcard characters: False 96 | ``` 97 | 98 | ### -ChatID 99 | Unique identifier for the target chat 100 | 101 | ```yaml 102 | Type: String 103 | Parameter Sets: (All) 104 | Aliases: 105 | 106 | Required: True 107 | Position: 2 108 | Default value: None 109 | Accept pipeline input: False 110 | Accept wildcard characters: False 111 | ``` 112 | 113 | ### -MediaType 114 | Type of media to send 115 | 116 | ```yaml 117 | Type: String 118 | Parameter Sets: (All) 119 | Aliases: 120 | 121 | Required: True 122 | Position: 3 123 | Default value: None 124 | Accept pipeline input: False 125 | Accept wildcard characters: False 126 | ``` 127 | 128 | ### -FilePaths 129 | List of filepaths for media you want to send 130 | 131 | ```yaml 132 | Type: String[] 133 | Parameter Sets: (All) 134 | Aliases: 135 | 136 | Required: False 137 | Position: 4 138 | Default value: None 139 | Accept pipeline input: False 140 | Accept wildcard characters: False 141 | ``` 142 | 143 | ### -DisableNotification 144 | Send the message silently. 145 | Users will receive a notification with no sound. 146 | 147 | ```yaml 148 | Type: SwitchParameter 149 | Parameter Sets: (All) 150 | Aliases: 151 | 152 | Required: False 153 | Position: Named 154 | Default value: False 155 | Accept pipeline input: False 156 | Accept wildcard characters: False 157 | ``` 158 | 159 | ### -ProtectContent 160 | Protects the contents of the sent message from forwarding and saving 161 | 162 | ```yaml 163 | Type: SwitchParameter 164 | Parameter Sets: (All) 165 | Aliases: 166 | 167 | Required: False 168 | Position: Named 169 | Default value: False 170 | Accept pipeline input: False 171 | Accept wildcard characters: False 172 | ``` 173 | 174 | ### CommonParameters 175 | This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. 176 | For more information, see about_CommonParameters (http://go.microsoft.com/fwlink/?LinkID=113216). 177 | 178 | ## INPUTS 179 | 180 | ## OUTPUTS 181 | 182 | ### System.Management.Automation.PSCustomObject 183 | ## NOTES 184 | Author: Jake Morrison - @jakemorrison - https://www.techthoughts.info/ 185 | This works with PowerShell Version: 6.1+ 186 | 187 | The following photo types are supported: 188 | JPG, JPEG, PNG, GIF, BMP, WEBP, SVG, TIFF 189 | 190 | The following video types are supported: 191 | Telegram clients support mp4 videos 192 | 193 | The following audio types are supported: 194 | MP3, M4A 195 | 196 | Questions on how to set up a bot, get a token, or get your channel ID? 197 | Answers on the PoshGram documentation: https://poshgram.readthedocs.io/en/latest/PoshGram-FAQ/ 198 | 199 | ? 200 | This was really hard to make. 201 | 202 | ## RELATED LINKS 203 | 204 | [https://poshgram.readthedocs.io/en/latest/Send-TelegramMediaGroup](https://poshgram.readthedocs.io/en/latest/Send-TelegramMediaGroup) 205 | 206 | [https://core.telegram.org/bots/api#sendmediagroup](https://core.telegram.org/bots/api#sendmediagroup) 207 | 208 | [https://core.telegram.org/bots/api](https://core.telegram.org/bots/api) 209 | 210 | -------------------------------------------------------------------------------- /docs/Send-TelegramURLPhoto.md: -------------------------------------------------------------------------------- 1 | --- 2 | external help file: PoshGram-help.xml 3 | Module Name: PoshGram 4 | online version: https://poshgram.readthedocs.io/en/latest/Send-TelegramURLPhoto 5 | schema: 2.0.0 6 | --- 7 | 8 | # Send-TelegramURLPhoto 9 | 10 | ## SYNOPSIS 11 | Sends Telegram photo message via Bot API from URL sourced photo image 12 | 13 | ## SYNTAX 14 | 15 | ``` 16 | Send-TelegramURLPhoto [-BotToken] [-ChatID] [-PhotoURL] [[-Caption] ] 17 | [[-ParseMode] ] [-DisableNotification] [-ProtectContent] [] 18 | ``` 19 | 20 | ## DESCRIPTION 21 | Uses Telegram Bot API to send photo message to specified Telegram chat. 22 | The photo will be sourced from the provided URL and sent to Telegram. 23 | Several options can be specified to adjust message parameters. 24 | 25 | ## EXAMPLES 26 | 27 | ### EXAMPLE 1 28 | ``` 29 | $botToken = 'nnnnnnnnn:xxxxxxx-xxxxxxxxxxxxxxxxxxxxxxxxxxx' 30 | $chatID = '-nnnnnnnnn' 31 | $photoURL = 'https://github.com/techthoughts2/PoshGram/raw/main/test/SourceFiles/techthoughts.png' 32 | Send-TelegramURLPhoto -BotToken $botToken -ChatID $chatID -PhotoURL $photourl 33 | ``` 34 | 35 | Sends photo message via Telegram API 36 | 37 | ### EXAMPLE 2 38 | ``` 39 | $botToken = 'nnnnnnnnn:xxxxxxx-xxxxxxxxxxxxxxxxxxxxxxxxxxx' 40 | $chatID = '-nnnnnnnnn' 41 | $photoURL = 'https://github.com/techthoughts2/PoshGram/raw/main/test/SourceFiles/techthoughts.png' 42 | $sendTelegramURLPhotoSplat = @{ 43 | BotToken = $botToken 44 | ChatID = $chatID 45 | PhotoURL = $photourl 46 | Caption = 'DSC is a great technology' 47 | ParseMode = 'MarkdownV2' 48 | DisableNotification = $true 49 | ProtectContent = $true 50 | Verbose = $true 51 | } 52 | Send-TelegramURLPhoto @sendTelegramURLPhotoSplat 53 | ``` 54 | 55 | Sends photo message via Telegram API 56 | 57 | ### EXAMPLE 3 58 | ``` 59 | $botToken = 'nnnnnnnnn:xxxxxxx-xxxxxxxxxxxxxxxxxxxxxxxxxxx' 60 | $chatID = '-nnnnnnnnn' 61 | $photoURL = 'https://github.com/techthoughts2/PoshGram/raw/main/test/SourceFiles/techthoughts.png' 62 | $sendTelegramURLPhotoSplat = @{ 63 | BotToken = $botToken 64 | ChatID = $chatID 65 | PhotoURL = $photourl 66 | Caption = "DSC is a __great__ technology\." 67 | ParseMode = 'MarkdownV2' 68 | } 69 | Send-TelegramURLPhoto @sendTelegramURLPhotoSplat 70 | ``` 71 | 72 | Sends photo message via Telegram API with properly formatted underlined word and escaped special character. 73 | 74 | ## PARAMETERS 75 | 76 | ### -BotToken 77 | Use this token to access the HTTP API 78 | 79 | ```yaml 80 | Type: String 81 | Parameter Sets: (All) 82 | Aliases: 83 | 84 | Required: True 85 | Position: 1 86 | Default value: None 87 | Accept pipeline input: False 88 | Accept wildcard characters: False 89 | ``` 90 | 91 | ### -ChatID 92 | Unique identifier for the target chat 93 | 94 | ```yaml 95 | Type: String 96 | Parameter Sets: (All) 97 | Aliases: 98 | 99 | Required: True 100 | Position: 2 101 | Default value: None 102 | Accept pipeline input: False 103 | Accept wildcard characters: False 104 | ``` 105 | 106 | ### -PhotoURL 107 | URL path to photo 108 | 109 | ```yaml 110 | Type: String 111 | Parameter Sets: (All) 112 | Aliases: 113 | 114 | Required: True 115 | Position: 3 116 | Default value: None 117 | Accept pipeline input: False 118 | Accept wildcard characters: False 119 | ``` 120 | 121 | ### -Caption 122 | Brief title or explanation for media 123 | 124 | ```yaml 125 | Type: String 126 | Parameter Sets: (All) 127 | Aliases: 128 | 129 | Required: False 130 | Position: 4 131 | Default value: None 132 | Accept pipeline input: False 133 | Accept wildcard characters: False 134 | ``` 135 | 136 | ### -ParseMode 137 | Send Markdown or HTML, if you want Telegram apps to show bold, italic, fixed-width text or inline URLs in your bot's message. 138 | Default is HTML. 139 | 140 | ```yaml 141 | Type: String 142 | Parameter Sets: (All) 143 | Aliases: 144 | 145 | Required: False 146 | Position: 5 147 | Default value: HTML 148 | Accept pipeline input: False 149 | Accept wildcard characters: False 150 | ``` 151 | 152 | ### -DisableNotification 153 | Send the message silently. 154 | Users will receive a notification with no sound. 155 | 156 | ```yaml 157 | Type: SwitchParameter 158 | Parameter Sets: (All) 159 | Aliases: 160 | 161 | Required: False 162 | Position: Named 163 | Default value: False 164 | Accept pipeline input: False 165 | Accept wildcard characters: False 166 | ``` 167 | 168 | ### -ProtectContent 169 | Protects the contents of the sent message from forwarding and saving 170 | 171 | ```yaml 172 | Type: SwitchParameter 173 | Parameter Sets: (All) 174 | Aliases: 175 | 176 | Required: False 177 | Position: Named 178 | Default value: False 179 | Accept pipeline input: False 180 | Accept wildcard characters: False 181 | ``` 182 | 183 | ### CommonParameters 184 | This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. 185 | For more information, see about_CommonParameters (http://go.microsoft.com/fwlink/?LinkID=113216). 186 | 187 | ## INPUTS 188 | 189 | ## OUTPUTS 190 | 191 | ### System.Management.Automation.PSCustomObject 192 | ## NOTES 193 | Author: Jake Morrison - @jakemorrison - https://www.techthoughts.info/ 194 | 195 | Questions on how to set up a bot, get a token, or get your channel ID? 196 | Answers on the PoshGram documentation: https://poshgram.readthedocs.io/en/latest/PoshGram-FAQ/ 197 | 198 | ## RELATED LINKS 199 | 200 | [https://poshgram.readthedocs.io/en/latest/Send-TelegramURLPhoto](https://poshgram.readthedocs.io/en/latest/Send-TelegramURLPhoto) 201 | 202 | [https://core.telegram.org/bots/api#sendphoto](https://core.telegram.org/bots/api#sendphoto) 203 | 204 | [https://core.telegram.org/bots/api#html-style](https://core.telegram.org/bots/api#html-style) 205 | 206 | [https://core.telegram.org/bots/api#markdownv2-style](https://core.telegram.org/bots/api#markdownv2-style) 207 | 208 | [https://core.telegram.org/bots/api#markdown-style](https://core.telegram.org/bots/api#markdown-style) 209 | 210 | [https://core.telegram.org/bots/api](https://core.telegram.org/bots/api) 211 | 212 | -------------------------------------------------------------------------------- /docs/Send-TelegramURLSticker.md: -------------------------------------------------------------------------------- 1 | --- 2 | external help file: PoshGram-help.xml 3 | Module Name: PoshGram 4 | online version: https://poshgram.readthedocs.io/en/latest/Send-TelegramURLSticker 5 | schema: 2.0.0 6 | --- 7 | 8 | # Send-TelegramURLSticker 9 | 10 | ## SYNOPSIS 11 | Sends Telegram sticker message via Bot API from URL sourced sticker image 12 | 13 | ## SYNTAX 14 | 15 | ``` 16 | Send-TelegramURLSticker [-BotToken] [-ChatID] [-StickerURL] [-DisableNotification] 17 | [-ProtectContent] [] 18 | ``` 19 | 20 | ## DESCRIPTION 21 | Uses Telegram Bot API to send sticker message to specified Telegram chat. 22 | The sticker will be sourced from the provided URL and sent to Telegram. 23 | 24 | ## EXAMPLES 25 | 26 | ### EXAMPLE 1 27 | ``` 28 | $botToken = 'nnnnnnnnn:xxxxxxx-xxxxxxxxxxxxxxxxxxxxxxxxxxx' 29 | $chatID = '-nnnnnnnnn' 30 | $stickerURL = 'https://github.com/techthoughts2/PoshGram/raw/main/test/SourceFiles/techthoughts.webp' 31 | Send-TelegramURLSticker -BotToken $botToken -ChatID $chatID -StickerURL $stickerURL 32 | ``` 33 | 34 | Sends sticker message via Telegram API 35 | 36 | ### EXAMPLE 2 37 | ``` 38 | $botToken = 'nnnnnnnnn:xxxxxxx-xxxxxxxxxxxxxxxxxxxxxxxxxxx' 39 | $chatID = '-nnnnnnnnn' 40 | $stickerURL = 'https://github.com/techthoughts2/PoshGram/raw/main/test/SourceFiles/techthoughts.webp' 41 | $sendTelegramURLStickerSplat = @{ 42 | BotToken = $botToken 43 | ChatID = $chatID 44 | StickerURL = $stickerURL 45 | DisableNotification = $true 46 | ProtectContent = $true 47 | Verbose = $true 48 | } 49 | Send-TelegramURLSticker @sendTelegramURLStickerSplat 50 | ``` 51 | 52 | Sends sticker message via Telegram API 53 | 54 | ## PARAMETERS 55 | 56 | ### -BotToken 57 | Use this token to access the HTTP API 58 | 59 | ```yaml 60 | Type: String 61 | Parameter Sets: (All) 62 | Aliases: 63 | 64 | Required: True 65 | Position: 1 66 | Default value: None 67 | Accept pipeline input: False 68 | Accept wildcard characters: False 69 | ``` 70 | 71 | ### -ChatID 72 | Unique identifier for the target chat 73 | 74 | ```yaml 75 | Type: String 76 | Parameter Sets: (All) 77 | Aliases: 78 | 79 | Required: True 80 | Position: 2 81 | Default value: None 82 | Accept pipeline input: False 83 | Accept wildcard characters: False 84 | ``` 85 | 86 | ### -StickerURL 87 | URL path to sticker 88 | 89 | ```yaml 90 | Type: String 91 | Parameter Sets: (All) 92 | Aliases: 93 | 94 | Required: True 95 | Position: 3 96 | Default value: None 97 | Accept pipeline input: False 98 | Accept wildcard characters: False 99 | ``` 100 | 101 | ### -DisableNotification 102 | Send the message silently. 103 | Users will receive a notification with no sound. 104 | 105 | ```yaml 106 | Type: SwitchParameter 107 | Parameter Sets: (All) 108 | Aliases: 109 | 110 | Required: False 111 | Position: Named 112 | Default value: False 113 | Accept pipeline input: False 114 | Accept wildcard characters: False 115 | ``` 116 | 117 | ### -ProtectContent 118 | Protects the contents of the sent message from forwarding and saving 119 | 120 | ```yaml 121 | Type: SwitchParameter 122 | Parameter Sets: (All) 123 | Aliases: 124 | 125 | Required: False 126 | Position: Named 127 | Default value: False 128 | Accept pipeline input: False 129 | Accept wildcard characters: False 130 | ``` 131 | 132 | ### CommonParameters 133 | This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. 134 | For more information, see about_CommonParameters (http://go.microsoft.com/fwlink/?LinkID=113216). 135 | 136 | ## INPUTS 137 | 138 | ## OUTPUTS 139 | 140 | ### System.Management.Automation.PSCustomObject 141 | ## NOTES 142 | Author: Jake Morrison - @jakemorrison - https://www.techthoughts.info/ 143 | 144 | The following sticker types are supported: 145 | WEBP, WEBM 146 | 147 | Questions on how to set up a bot, get a token, or get your channel ID? 148 | Answers on the PoshGram documentation: https://poshgram.readthedocs.io/en/latest/PoshGram-FAQ/ 149 | 150 | ## RELATED LINKS 151 | 152 | [https://poshgram.readthedocs.io/en/latest/Send-TelegramURLSticker](https://poshgram.readthedocs.io/en/latest/Send-TelegramURLSticker) 153 | 154 | [https://core.telegram.org/bots/api#sendsticker](https://core.telegram.org/bots/api#sendsticker) 155 | 156 | [https://core.telegram.org/bots/api](https://core.telegram.org/bots/api) 157 | 158 | -------------------------------------------------------------------------------- /docs/Send-TelegramVenue.md: -------------------------------------------------------------------------------- 1 | --- 2 | external help file: PoshGram-help.xml 3 | Module Name: PoshGram 4 | online version: https://poshgram.readthedocs.io/en/latest/Send-TelegramVenue 5 | schema: 2.0.0 6 | --- 7 | 8 | # Send-TelegramVenue 9 | 10 | ## SYNOPSIS 11 | Sends Telegram information about a venue. 12 | 13 | ## SYNTAX 14 | 15 | ``` 16 | Send-TelegramVenue [-BotToken] [-ChatID] [-Latitude] [-Longitude] 17 | [-Title] [-Address] [-DisableNotification] [-ProtectContent] [] 18 | ``` 19 | 20 | ## DESCRIPTION 21 | Uses Telegram Bot API to send latitude, longitude, title, and address information about a venue to specified Telegram chat. 22 | 23 | ## EXAMPLES 24 | 25 | ### EXAMPLE 1 26 | ``` 27 | $botToken = 'nnnnnnnnn:xxxxxxx-xxxxxxxxxxxxxxxxxxxxxxxxxxx' 28 | $chatID = '-nnnnnnnnn' 29 | $latitude = 37.621313 30 | $longitude = -122.378955 31 | $title = 'Star Fleet Headquarters' 32 | $address = 'San Francisco, CA 94128' 33 | Send-TelegramVenue -BotToken $botToken -ChatID $chatID -Latitude $latitude -Longitude $longitude -Title $title -Address $address 34 | ``` 35 | 36 | Sends venue information via Telegram API 37 | 38 | ### EXAMPLE 2 39 | ``` 40 | $botToken = 'nnnnnnnnn:xxxxxxx-xxxxxxxxxxxxxxxxxxxxxxxxxxx' 41 | $chatID = '-nnnnnnnnn' 42 | $latitude = 37.621313 43 | $longitude = -122.378955 44 | $title = 'Star Fleet Headquarters' 45 | $address = 'San Francisco, CA 94128' 46 | $sendTelegramVenueSplat = @{ 47 | BotToken = $botToken 48 | ChatID = $chatID 49 | Latitude = $latitude 50 | Longitude = $longitude 51 | Title = $title 52 | Address = $address 53 | DisableNotification = $true 54 | ProtectContent = $true 55 | Verbose = $true 56 | } 57 | Send-TelegramVenue @sendTelegramVenueSplat 58 | ``` 59 | 60 | Sends venue information via Telegram API 61 | 62 | ## PARAMETERS 63 | 64 | ### -BotToken 65 | Use this token to access the HTTP API 66 | 67 | ```yaml 68 | Type: String 69 | Parameter Sets: (All) 70 | Aliases: 71 | 72 | Required: True 73 | Position: 1 74 | Default value: None 75 | Accept pipeline input: False 76 | Accept wildcard characters: False 77 | ``` 78 | 79 | ### -ChatID 80 | Unique identifier for the target chat 81 | 82 | ```yaml 83 | Type: String 84 | Parameter Sets: (All) 85 | Aliases: 86 | 87 | Required: True 88 | Position: 2 89 | Default value: None 90 | Accept pipeline input: False 91 | Accept wildcard characters: False 92 | ``` 93 | 94 | ### -Latitude 95 | Latitude of the venue 96 | 97 | ```yaml 98 | Type: Single 99 | Parameter Sets: (All) 100 | Aliases: 101 | 102 | Required: True 103 | Position: 3 104 | Default value: 0 105 | Accept pipeline input: False 106 | Accept wildcard characters: False 107 | ``` 108 | 109 | ### -Longitude 110 | Longitude of the venue 111 | 112 | ```yaml 113 | Type: Single 114 | Parameter Sets: (All) 115 | Aliases: 116 | 117 | Required: True 118 | Position: 4 119 | Default value: 0 120 | Accept pipeline input: False 121 | Accept wildcard characters: False 122 | ``` 123 | 124 | ### -Title 125 | Name of the venue 126 | 127 | ```yaml 128 | Type: String 129 | Parameter Sets: (All) 130 | Aliases: 131 | 132 | Required: True 133 | Position: 5 134 | Default value: None 135 | Accept pipeline input: False 136 | Accept wildcard characters: False 137 | ``` 138 | 139 | ### -Address 140 | Address of the venue 141 | 142 | ```yaml 143 | Type: String 144 | Parameter Sets: (All) 145 | Aliases: 146 | 147 | Required: True 148 | Position: 6 149 | Default value: None 150 | Accept pipeline input: False 151 | Accept wildcard characters: False 152 | ``` 153 | 154 | ### -DisableNotification 155 | Send the message silently. 156 | Users will receive a notification with no sound. 157 | 158 | ```yaml 159 | Type: SwitchParameter 160 | Parameter Sets: (All) 161 | Aliases: 162 | 163 | Required: False 164 | Position: Named 165 | Default value: False 166 | Accept pipeline input: False 167 | Accept wildcard characters: False 168 | ``` 169 | 170 | ### -ProtectContent 171 | Protects the contents of the sent message from forwarding and saving 172 | 173 | ```yaml 174 | Type: SwitchParameter 175 | Parameter Sets: (All) 176 | Aliases: 177 | 178 | Required: False 179 | Position: Named 180 | Default value: False 181 | Accept pipeline input: False 182 | Accept wildcard characters: False 183 | ``` 184 | 185 | ### CommonParameters 186 | This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. 187 | For more information, see about_CommonParameters (http://go.microsoft.com/fwlink/?LinkID=113216). 188 | 189 | ## INPUTS 190 | 191 | ## OUTPUTS 192 | 193 | ### System.Management.Automation.PSCustomObject 194 | ## NOTES 195 | Author: Jake Morrison - @jakemorrison - https://www.techthoughts.info/ 196 | 197 | Questions on how to set up a bot, get a token, or get your channel ID? 198 | Answers on the PoshGram documentation: https://poshgram.readthedocs.io/en/latest/PoshGram-FAQ/ 199 | 200 | ## RELATED LINKS 201 | 202 | [https://poshgram.readthedocs.io/en/latest/Send-TelegramVenue](https://poshgram.readthedocs.io/en/latest/Send-TelegramVenue) 203 | 204 | [https://core.telegram.org/bots/api#sendvenue](https://core.telegram.org/bots/api#sendvenue) 205 | 206 | [https://core.telegram.org/bots/api](https://core.telegram.org/bots/api) 207 | 208 | -------------------------------------------------------------------------------- /docs/Test-BotToken.md: -------------------------------------------------------------------------------- 1 | --- 2 | external help file: PoshGram-help.xml 3 | Module Name: PoshGram 4 | online version: https://poshgram.readthedocs.io/en/latest/Test-BotToken 5 | schema: 2.0.0 6 | --- 7 | 8 | # Test-BotToken 9 | 10 | ## SYNOPSIS 11 | Validates Bot auth Token 12 | 13 | ## SYNTAX 14 | 15 | ``` 16 | Test-BotToken [-BotToken] [] 17 | ``` 18 | 19 | ## DESCRIPTION 20 | A simple method for testing your bot's auth token. 21 | Requires no parameters. 22 | Returns basic information about the bot in form of a User object. 23 | 24 | ## EXAMPLES 25 | 26 | ### EXAMPLE 1 27 | ``` 28 | $botToken = 'nnnnnnnnn:xxxxxxx-xxxxxxxxxxxxxxxxxxxxxxxxxxx' 29 | Test-BotToken -BotToken $botToken 30 | ``` 31 | 32 | Validates the specified Bot auth token via Telegram API 33 | 34 | ### EXAMPLE 2 35 | ``` 36 | $botToken = 'nnnnnnnnn:xxxxxxx-xxxxxxxxxxxxxxxxxxxxxxxxxxx' 37 | $testBotTokenSplat = @{ 38 | BotToken = $botToken 39 | Verbose = $true 40 | } 41 | Test-BotToken @testBotTokenSplat 42 | ``` 43 | 44 | Validates the specified Bot auth token via Telegram API 45 | 46 | ## PARAMETERS 47 | 48 | ### -BotToken 49 | Use this token to access the HTTP API 50 | 51 | ```yaml 52 | Type: String 53 | Parameter Sets: (All) 54 | Aliases: 55 | 56 | Required: True 57 | Position: 1 58 | Default value: None 59 | Accept pipeline input: False 60 | Accept wildcard characters: False 61 | ``` 62 | 63 | ### CommonParameters 64 | This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. 65 | For more information, see about_CommonParameters (http://go.microsoft.com/fwlink/?LinkID=113216). 66 | 67 | ## INPUTS 68 | 69 | ## OUTPUTS 70 | 71 | ### System.Management.Automation.PSCustomObject 72 | ## NOTES 73 | Author: Jake Morrison - @jakemorrison - https://www.techthoughts.info/ 74 | 75 | Questions on how to set up a bot, get a token, or get your channel ID? 76 | Answers on the PoshGram documentation: https://poshgram.readthedocs.io/en/latest/PoshGram-FAQ/ 77 | 78 | ## RELATED LINKS 79 | 80 | [https://poshgram.readthedocs.io/en/latest/Test-BotToken](https://poshgram.readthedocs.io/en/latest/Test-BotToken) 81 | 82 | [https://core.telegram.org/bots/api#getme](https://core.telegram.org/bots/api#getme) 83 | 84 | [https://core.telegram.org/bots/api](https://core.telegram.org/bots/api) 85 | 86 | -------------------------------------------------------------------------------- /docs/assets/PoshGram.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/techthoughts2/PoshGram/575cbd2ca7faf060feeb3c21d9b84441fdbae646/docs/assets/PoshGram.gif -------------------------------------------------------------------------------- /docs/assets/PoshGram.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/techthoughts2/PoshGram/575cbd2ca7faf060feeb3c21d9b84441fdbae646/docs/assets/PoshGram.png -------------------------------------------------------------------------------- /docs/assets/PoshGram_favicon_32x32.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/techthoughts2/PoshGram/575cbd2ca7faf060feeb3c21d9b84441fdbae646/docs/assets/PoshGram_favicon_32x32.png -------------------------------------------------------------------------------- /docs/assets/PoshGram_icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/techthoughts2/PoshGram/575cbd2ca7faf060feeb3c21d9b84441fdbae646/docs/assets/PoshGram_icon.png -------------------------------------------------------------------------------- /docs/assets/telegram_custom_keyboard.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/techthoughts2/PoshGram/575cbd2ca7faf060feeb3c21d9b84441fdbae646/docs/assets/telegram_custom_keyboard.png -------------------------------------------------------------------------------- /docs/assets/telegram_inline_keyboard.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/techthoughts2/PoshGram/575cbd2ca7faf060feeb3c21d9b84441fdbae646/docs/assets/telegram_inline_keyboard.png -------------------------------------------------------------------------------- /docs/assets/telegram_share_stickers.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/techthoughts2/PoshGram/575cbd2ca7faf060feeb3c21d9b84441fdbae646/docs/assets/telegram_share_stickers.png -------------------------------------------------------------------------------- /docs/assets/telegram_view_sticker_set.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/techthoughts2/PoshGram/575cbd2ca7faf060feeb3c21d9b84441fdbae646/docs/assets/telegram_view_sticker_set.png -------------------------------------------------------------------------------- /docs/requirements.txt: -------------------------------------------------------------------------------- 1 | # https://github.com/readthedocs-examples/example-mkdocs-basic/blob/main/docs/requirements.txt 2 | # requirements.txt 3 | jinja2==3.0.3 4 | mkdocs>=1.4.2 5 | mkdocs-material>=9.0.12 #https://github.com/squidfunk/mkdocs-material 6 | pygments>=2.14.0 7 | # mdx_truly_sane_lists 8 | -------------------------------------------------------------------------------- /mkdocs.yml: -------------------------------------------------------------------------------- 1 | # https://www.mkdocs.org/user-guide/configuration/ 2 | # https://www.mkdocs.org/user-guide/writing-your-docs/ 3 | # https://www.mkdocs.org/user-guide/writing-your-docs/#writing-with-markdown 4 | # https://mkdocs.readthedocs.io/en/0.15.2/user-guide/writing-your-docs/ 5 | # https://mkdocs.readthedocs.io/en/0.15.2/user-guide/styling-your-docs/ 6 | # https://example-mkdocs-basic.readthedocs.io/en/latest/ 7 | # https://github.com/mkdocs/mkdocs/blob/master/mkdocs.yml 8 | # https://squidfunk.github.io/mkdocs-material/creating-your-site/ 9 | # mkdocs.yml 10 | 11 | site_name: PoshGram 12 | # site_url: 13 | repo_url: https://github.com/techthoughts2/PoshGram 14 | # repo_name: 15 | # edit_uri: edit/main/docs/ 16 | # edit_uri_template: 17 | site_description: PoshGram - A PowerShell Module for Telegram Bot API - Automate Messaging, Alerts, and Chat Interactions in PowerShell with Telegram. # meta tag to the generated HTML header 18 | site_author: Jake Morrison # meta tag to the generated HTML header 19 | copyright: "PoshGram is licensed under the MIT license" 20 | # remote_branch: 21 | # remote_name: 22 | # docs_dir: docs 23 | # site_dir: 24 | # extra_css: 25 | # extra_javascript: 26 | markdown_extensions: 27 | # Python Markdown 28 | - admonition 29 | - toc: 30 | permalink: true 31 | # code highlighting 32 | - pymdownx.highlight: 33 | use_pygments: true 34 | - pymdownx.highlight: 35 | anchor_linenums: true 36 | - pymdownx.inlinehilite 37 | - pymdownx.snippets 38 | - pymdownx.superfences 39 | 40 | # extra_templates: 41 | # extra: 42 | theme: 43 | name: material 44 | language: en 45 | # custom_dir: overrides 46 | features: 47 | # - navigation.tabs 48 | # - navigation.tabs.sticky 49 | # - navigation.path 50 | favicon: assets/PoshGram_favicon_32x32.png 51 | # icon: 52 | # repo: 53 | # font: 54 | # text: Work Sans 55 | logo: assets/PoshGram_favicon_32x32.png 56 | # palette: 57 | # primary: teal 58 | # palette: 59 | # # Palette toggle for light mode 60 | # - media: "(prefers-color-scheme: light)" 61 | # scheme: default 62 | # primary: light blue 63 | # accent: pink 64 | # toggle: 65 | # icon: material/brightness-7 66 | # name: Switch to dark mode 67 | 68 | # # Palette toggle for dark mode 69 | # - media: "(prefers-color-scheme: dark)" 70 | # scheme: slate 71 | # primary: indigo 72 | # accent: pink 73 | # toggle: 74 | # icon: material/brightness-4 75 | # name: Switch to light mode 76 | nav: 77 | - Home: index.md 78 | - Usage: 79 | - PoshGram Basics: PoshGram-Basics.md 80 | - PoshGram Advanced: PoshGram-Advanced.md 81 | - PoshGram Stickers: PoshGram-Sticker-Info.md 82 | - Functions: 83 | - Send-TelegramTextMessage: Send-TelegramTextMessage.md 84 | - Send-TelegramContact: Send-TelegramContact.md 85 | - Send-TelegramDice: Send-TelegramDice.md 86 | - Send-TelegramPoll: Send-TelegramPoll.md 87 | - Send-TelegramLocation: Send-TelegramLocation.md 88 | - Send-TelegramVenue: Send-TelegramVenue.md 89 | - Test-BotToken: Test-BotToken.md 90 | - Media: 91 | - Send-TelegramMediaGroup: Send-TelegramMediaGroup.md 92 | - Animation: 93 | - Send-TelegramLocalAnimation: Send-TelegramLocalAnimation.md 94 | - Send-TelegramURLAnimation: Send-TelegramURLAnimation.md 95 | - Audio: 96 | - Send-TelegramLocalAudio: Send-TelegramLocalAudio.md 97 | - Send-TelegramURLAudio: Send-TelegramURLAudio.md 98 | - Document: 99 | - Send-TelegramLocalDocument: Send-TelegramLocalDocument.md 100 | - Send-TelegramURLDocument: Send-TelegramURLDocument.md 101 | - Photo: 102 | - Send-TelegramLocalPhoto: Send-TelegramLocalPhoto.md 103 | - Send-TelegramURLPhoto: Send-TelegramURLPhoto.md 104 | - Video: 105 | - Send-TelegramLocalVideo: Send-TelegramLocalVideo.md 106 | - Send-TelegramURLVideo: Send-TelegramURLVideo.md 107 | - Stickers: 108 | - Get-TelegramCustomEmojiStickerInfo: Get-TelegramCustomEmojiStickerInfo.md 109 | - Get-TelegramStickerPackInfo: Get-TelegramStickerPackInfo.md 110 | - Send-TelegramSticker: Send-TelegramSticker.md 111 | - Send-TelegramLocalSticker: Send-TelegramLocalSticker.md 112 | - Send-TelegramURLSticker: Send-TelegramURLSticker.md 113 | - Setting Up Telegram Bot: PoshGram-Telegram-API.md 114 | - FAQ: PoshGram-FAQ.md 115 | - Change Log: CHANGELOG.md 116 | -------------------------------------------------------------------------------- /src/PSScriptAnalyzerSettings.psd1: -------------------------------------------------------------------------------- 1 | @{ 2 | #________________________________________ 3 | #IncludeDefaultRules 4 | IncludeDefaultRules = $true 5 | #________________________________________ 6 | #Severity 7 | #Specify Severity when you want to limit generated diagnostic records to a specific subset: [ Error | Warning | Information ] 8 | Severity = @('Error', 'Warning') 9 | #________________________________________ 10 | #CustomRulePath 11 | #Specify CustomRulePath when you have a large set of custom rules you'd like to reference 12 | #CustomRulePath = "Module\InjectionHunter\1.0.0\InjectionHunter.psd1" 13 | #________________________________________ 14 | #IncludeRules 15 | #Specify IncludeRules when you only want to run specific subset of rules instead of the default rule set. 16 | #IncludeRules = @('PSShouldProcess', 17 | # 'PSUseApprovedVerbs') 18 | #________________________________________ 19 | #ExcludeRules 20 | #Specify ExcludeRules when you want to exclude a certain rule from the the default set of rules. 21 | #ExcludeRule = @( 22 | # 'PSUseDeclaredVarsMoreThanAssignments' 23 | #) 24 | #________________________________________ 25 | #Rules 26 | #Here you can specify customizations for particular rules. Several examples are included below: 27 | #Rules = @{ 28 | # PSUseCompatibleCmdlets = @{ 29 | # compatibility = @('core-6.1.0-windows', 'desktop-4.0-windows') 30 | # } 31 | # PSUseCompatibleSyntax = @{ 32 | # Enable = $true 33 | # TargetVersions = @( 34 | # '3.0', 35 | # '5.1', 36 | # '6.2' 37 | # ) 38 | # } 39 | # PSUseCompatibleCommands = @{ 40 | # Enable = $true 41 | # TargetProfiles = @( 42 | # 'win-8_x64_10.0.14393.0_6.1.3_x64_4.0.30319.42000_core', # PS 6.1 on WinServer-2019 43 | # 'win-8_x64_10.0.17763.0_5.1.17763.316_x64_4.0.30319.42000_framework', # PS 5.1 on WinServer-2019 44 | # 'win-8_x64_6.2.9200.0_3.0_x64_4.0.30319.42000_framework' # PS 3 on WinServer-2012 45 | # ) 46 | # } 47 | # PSUseCompatibleTypes = @{ 48 | # Enable = $true 49 | # TargetProfiles = @( 50 | # 'ubuntu_x64_18.04_6.1.3_x64_4.0.30319.42000_core', 51 | # 'win-48_x64_10.0.17763.0_5.1.17763.316_x64_4.0.30319.42000_framework' 52 | # ) 53 | # # You can specify types to not check like this, which will also ignore methods and members on it: 54 | # IgnoreTypes = @( 55 | # 'System.IO.Compression.ZipFile' 56 | # ) 57 | # } 58 | #} 59 | #________________________________________ 60 | } 61 | -------------------------------------------------------------------------------- /src/PoshGram.Settings.ps1: -------------------------------------------------------------------------------- 1 | # specify the minumum required major PowerShell version that the build script should validate 2 | [int]$script:requiredPSVersion = '6.1' -------------------------------------------------------------------------------- /src/PoshGram/Imports.ps1: -------------------------------------------------------------------------------- 1 | # This is a locally sourced Imports file for local development. 2 | # It can be imported by the psm1 in local development to add script level variables. 3 | # It will merged in the build process. This is for local development only. 4 | 5 | # region script variables 6 | # $script:resourcePath = "$PSScriptRoot\Resources" 7 | -------------------------------------------------------------------------------- /src/PoshGram/PoshGram.psm1: -------------------------------------------------------------------------------- 1 | # this psm1 is for local testing and development use only 2 | 3 | # dot source the parent import for local development variables 4 | . $PSScriptRoot\Imports.ps1 5 | 6 | # discover all ps1 file(s) in Public and Private paths 7 | $itemSplat = @{ 8 | Filter = '*.ps1' 9 | Recurse = $true 10 | ErrorAction = 'Stop' 11 | } 12 | try { 13 | $public = @(Get-ChildItem -Path "$PSScriptRoot\Public" @itemSplat) 14 | $private = @(Get-ChildItem -Path "$PSScriptRoot\Private" @itemSplat) 15 | } 16 | catch { 17 | Write-Error $_ 18 | throw 'Unable to get get file information from Public & Private src.' 19 | } 20 | 21 | # dot source all .ps1 file(s) found 22 | foreach ($file in @($public + $private)) { 23 | try { 24 | . $file.FullName 25 | } 26 | catch { 27 | throw "Unable to dot source [$($file.FullName)]" 28 | 29 | } 30 | } 31 | 32 | # export all public functions 33 | Export-ModuleMember -Function $public.Basename -------------------------------------------------------------------------------- /src/PoshGram/Private/Add-EmojiDetail.ps1: -------------------------------------------------------------------------------- 1 | <# 2 | .SYNOPSIS 3 | Enriches the Telegram sticker object with additional emoji data. 4 | .DESCRIPTION 5 | Evaluates the emoji data for the specified emoji and adds it to the Telegram sticker object. 6 | .EXAMPLE 7 | Add-EmojiDetail -StickerObject $stickerObject 8 | 9 | Enriches the Telegram sticker object with additional emoji data. 10 | .PARAMETER StickerObject 11 | Telegram sticker object 12 | .OUTPUTS 13 | System.Management.Automation.PSCustomObject 14 | .NOTES 15 | Author: Jake Morrison - @jakemorrison - https://www.techthoughts.info/ 16 | .COMPONENT 17 | PoshGram 18 | #> 19 | function Add-EmojiDetail { 20 | [CmdletBinding()] 21 | param ( 22 | [Parameter(Mandatory = $true, 23 | HelpMessage = 'Telegram sticker object')] 24 | [object]$StickerObject 25 | ) 26 | 27 | try { 28 | $emojiData = Get-Emoji -Emoji $StickerObject.emoji 29 | } 30 | catch { 31 | Write-Warning -Message ('An error was encountered getting the emoji data for {0}' -f $StickerObject.emoji) 32 | Write-Error $_ 33 | } 34 | 35 | if ($emojiData) { 36 | Write-Debug -Message ('Emoji data found for {0}' -f $StickerObject.emoji) 37 | $StickerObject | Add-Member -Type NoteProperty -Name Group -Value $emojiData.Group -Force 38 | $StickerObject | Add-Member -Type NoteProperty -Name SubGroup -Value $emojiData.SubGroup -Force 39 | $StickerObject | Add-Member -Type NoteProperty -Name Code -Value $emojiData.UnicodeStandard -Force 40 | $StickerObject | Add-Member -Type NoteProperty -Name pwshEscapedFormat -Value $emojiData.pwshEscapedFormat -Force 41 | $StickerObject | Add-Member -Type NoteProperty -Name Shortcode -Value $emojiData.ShortCode -Force 42 | } 43 | else { 44 | Write-Debug -Message ('No emoji data found for {0}' -f $StickerObject.emoji) 45 | } 46 | 47 | return $StickerObject 48 | } #Add-EmojiDetail 49 | -------------------------------------------------------------------------------- /src/PoshGram/Private/Confirm-URL.ps1: -------------------------------------------------------------------------------- 1 | <# 2 | .SYNOPSIS 3 | Evaluates if the provided URL is reachable 4 | .DESCRIPTION 5 | Evaluates if the provided URL is reachable and returns a boolean based on results 6 | .EXAMPLE 7 | Confirm-URL -Uri http://gph.is/2y3AWRU 8 | 9 | Determines if the provided URL is accessible and returns a boolean based on results 10 | .PARAMETER Uri 11 | Uri you wish to resolve 12 | .OUTPUTS 13 | System.Boolean 14 | .NOTES 15 | Author: Jake Morrison - @jakemorrison - https://www.techthoughts.info/ 16 | .COMPONENT 17 | PoshGram 18 | #> 19 | function Confirm-URL { 20 | [CmdletBinding()] 21 | param ( 22 | ## The URI to resolve 23 | [Parameter(Mandatory = $true, 24 | HelpMessage = 'Uri you wish to resolve')] 25 | [string]$Uri 26 | ) 27 | $result = $true #assume the best 28 | [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12 29 | Write-Verbose -Message "Attempting to confirm $Uri" 30 | try { 31 | Invoke-WebRequest -Uri $uri -UseBasicParsing -DisableKeepAlive -ErrorAction Stop | Out-Null 32 | Write-Verbose -Message 'Confirmed.' 33 | } #try_Invoke-WebRequest 34 | catch { 35 | Write-Verbose -Message 'Catch on Invoke-WebRequest. This is not necessarily a bad thing. Checking status code.' 36 | if ([int]$_.Exception.Response.StatusCode -eq 0) { 37 | Write-Warning -Message "$Uri" 38 | Write-Warning -Message 'The URL provided does not appear to be valid' 39 | $result = $false 40 | } 41 | #we will proceed with any other exit code 42 | } #catch_Invoke-WebRequest 43 | return $result 44 | } #Confirm-URL 45 | -------------------------------------------------------------------------------- /src/PoshGram/Private/Resolve-ShortLink.ps1: -------------------------------------------------------------------------------- 1 | <# 2 | .SYNOPSIS 3 | Resolve a URI to the URIs it redirects to 4 | .DESCRIPTION 5 | Resolves a URI provided to the URI it redirects to. If no redirect is in place, null is returned. This is useful for resolving shortlinks to try url file paths. 6 | .EXAMPLE 7 | Resolve-ShortLink -Uri http://gph.is/2y3AWRU 8 | 9 | Resolve shortlink to full URI 10 | .PARAMETER Uri 11 | Uri you wish to resolve 12 | .OUTPUTS 13 | System.String 14 | -or- 15 | Null 16 | .NOTES 17 | Author: Jake Morrison - @jakemorrison - https://www.techthoughts.info/ 18 | .COMPONENT 19 | PoshGram 20 | #> 21 | function Resolve-ShortLink { 22 | [CmdletBinding()] 23 | param ( 24 | ## The URI to resolve 25 | [Parameter(Mandatory = $true, 26 | HelpMessage = 'Uri you wish to resolve')] 27 | [string]$Uri 28 | ) 29 | $result = $null 30 | $eval = $null 31 | [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12 32 | try { 33 | $eval = Invoke-WebRequest -Uri $uri -MaximumRedirection 0 -ErrorAction Stop 34 | } #try_Invoke-WebRequest 35 | catch { 36 | #if($_.ErrorDetails.Message -like "*maximum redirection*"){ 37 | if ($_.Exception.Message -like "*Moved*") { 38 | $eval = $_ 39 | Write-Verbose -Message 'Moved detected.' 40 | #$result = $eval.Headers.Location 41 | $result = $eval.Exception.Response.Headers.Location.AbsoluteUri 42 | } #if_Error_Moved 43 | else { 44 | Write-Warning -Message 'An Error was encountered resolving a potential shortlink:' 45 | Write-Error $_ 46 | } #else_Error_Moved 47 | } #catch_Invoke-WebRequest 48 | return $result 49 | } #Resolve-ShortLink 50 | -------------------------------------------------------------------------------- /src/PoshGram/Private/Test-Explanation.ps1: -------------------------------------------------------------------------------- 1 | <# 2 | .SYNOPSIS 3 | Verifies that provided quiz explanation matches Telegram requirements. 4 | .DESCRIPTION 5 | Evaluates if the provided quiz explanation meets the Telegram explanation requirements. 6 | .EXAMPLE 7 | Test-Explanation -Explanation $explanation 8 | 9 | Verifies if the provided options meet the poll requirements. 10 | .PARAMETER Explanation 11 | Quiz explanation text 12 | .OUTPUTS 13 | System.Boolean 14 | .NOTES 15 | Author: Jake Morrison - @jakemorrison - https://www.techthoughts.info/ 16 | Telegram currently supports 0-200 characters with at most 2 line feeds after entities parsing 17 | .COMPONENT 18 | PoshGram 19 | #> 20 | function Test-Explanation { 21 | [CmdletBinding()] 22 | param ( 23 | [Parameter(Mandatory = $true, 24 | HelpMessage = 'Quiz explanation text')] 25 | [string]$Explanation 26 | ) 27 | $results = $true #assume the best 28 | Write-Verbose -Message 'Evaluating provided explanation...' 29 | 30 | $splitTest = $Explanation -split '\n' 31 | $carriageCount = $splitTest | Measure-Object | Select-Object -ExpandProperty Count 32 | 33 | if ($carriageCount -gt 2) { 34 | Write-Warning -Message 'Explanation can contain at most 2 line feeds.' 35 | $results = $false 36 | } 37 | 38 | if ($Explanation.Length -gt 200) { 39 | Write-Warning -Message 'Explanation can contain at most 200 characters.' 40 | $results = $false 41 | } 42 | 43 | return $results 44 | } #function_Test-Explanation 45 | -------------------------------------------------------------------------------- /src/PoshGram/Private/Test-FileExtension.ps1: -------------------------------------------------------------------------------- 1 | <# 2 | .SYNOPSIS 3 | Verifies that specified file is a supported Telegram extension type 4 | .DESCRIPTION 5 | Evaluates the specified file path to determine if the file is a supported extension type 6 | .EXAMPLE 7 | Test-FileExtension -FilePath C:\photos\aphoto.jpg -Type Photo 8 | 9 | Verifies if the path specified is a supported photo extension type 10 | .EXAMPLE 11 | Test-FileExtension -FilePath $PhotoPath -Type Photo -Verbose 12 | 13 | Verifies if the path specified in $PhotoPath is a supported photo extension type with verbose output 14 | .EXAMPLE 15 | $fileTypeEval = Test-FileExtension -FilePath $AnimationPath -Type Animation 16 | 17 | Verifies if the path specified is a supported Animation extension type 18 | .EXAMPLE 19 | $fileTypeEval = Test-FileExtension -FilePath $Audio -Type Audio 20 | 21 | Verifies if the path specified is a supported Audio extension type 22 | .EXAMPLE 23 | $fileTypeEval = Test-FileExtension -FilePath $PhotoPath -Type Photo 24 | 25 | Verifies if the path specified is a supported photo extension type 26 | .EXAMPLE 27 | $fileTypeEval = Test-FileExtension -FilePath $Video -Type Video 28 | 29 | Verifies if the path specified is a supported Video extension type 30 | .EXAMPLE 31 | $fileTypeEval = Test-FileExtension -FilePath $Sticker -Type Sticker 32 | 33 | Verifies if the path specified is a supported Sticker extension type 34 | .PARAMETER FilePath 35 | Path to file that will be evaluated 36 | .PARAMETER Type 37 | Telegram message type 38 | .OUTPUTS 39 | System.Boolean 40 | .NOTES 41 | Author: Jake Morrison - @jakemorrison - https://www.techthoughts.info/ 42 | .COMPONENT 43 | PoshGram 44 | #> 45 | function Test-FileExtension { 46 | [CmdletBinding()] 47 | param ( 48 | [Parameter(Mandatory = $true, 49 | HelpMessage = 'Path to file that will be evaluated')] 50 | [ValidateNotNull()] 51 | [ValidateNotNullOrEmpty()] 52 | [string]$FilePath, 53 | [Parameter(Mandatory = $true, 54 | HelpMessage = 'Telegram message type')] 55 | [ValidateSet('Photo', 'Video', 'Audio', 'Animation', 'Sticker')] 56 | [string]$Type 57 | ) 58 | #------------------------------------------------------------ 59 | $supportedPhotoExtensions = @( 60 | 'JPG' 61 | 'JPEG' 62 | 'PNG' 63 | 'GIF' 64 | 'BMP' 65 | 'WEBP' 66 | 'SVG' 67 | 'TIFF' 68 | ) 69 | $supportedVideoExtensions = @( 70 | 'MP4' 71 | ) 72 | $supportedAudioExtensions = @( 73 | 'MP3', 74 | 'M4A' 75 | ) 76 | $supportedAnimationExtensions = @( 77 | 'GIF' 78 | ) 79 | $supportedStickerExtensions = @( 80 | 'WEBP' 81 | 'TGS' 82 | 'WEBM' 83 | ) 84 | switch ($Type) { 85 | Photo { 86 | $extType = $supportedPhotoExtensions 87 | } #photo 88 | Video { 89 | $extType = $supportedVideoExtensions 90 | } #video 91 | Audio { 92 | $extType = $supportedAudioExtensions 93 | } #audio 94 | Animation { 95 | $extType = $supportedAnimationExtensions 96 | } #animation 97 | Sticker { 98 | $extType = $supportedStickerExtensions 99 | } 100 | } #switch_Type 101 | Write-Verbose -Message "Validating type: $Type" 102 | #------------------------------------------------------------ 103 | [bool]$results = $true #assume the best. 104 | #------------------------------------------------------------ 105 | Write-Verbose -Message "Processing $FilePath ..." 106 | $divide = $FilePath.Split('.') 107 | $rawExtension = $divide[$divide.Length - 1] 108 | $extension = $rawExtension.ToUpper() 109 | Write-Verbose -Message "Verifying discovered extension: $extension" 110 | switch ($extension) { 111 | { $extType -contains $_ } { 112 | Write-Verbose -Message 'Extension verified.' 113 | } 114 | default { 115 | Write-Warning -Message "The specified file is not a supported $Type extension." 116 | $results = $false 117 | } #default 118 | } #switch_extension 119 | return $results 120 | } #function_Test-FileExtension 121 | -------------------------------------------------------------------------------- /src/PoshGram/Private/Test-FileSize.ps1: -------------------------------------------------------------------------------- 1 | <# 2 | .SYNOPSIS 3 | Verifies that file size is supported by Telegram 4 | .DESCRIPTION 5 | Evaluates if the file is at or below the supported Telegram file size 6 | .EXAMPLE 7 | Test-FileSize -Path C:\videos\video.mp4 8 | 9 | Verifies if the path specified is a supported video extension type 10 | .EXAMPLE 11 | Test-FileSize -Path $Path -Verbose 12 | 13 | Verifies if the path specified in $VideoPath is a supported video extension type with verbose output 14 | .PARAMETER Path 15 | Path to file 16 | .OUTPUTS 17 | System.Boolean 18 | .NOTES 19 | Author: Jake Morrison - @jakemorrison - https://www.techthoughts.info/ 20 | Telegram currently supports a 50MB file size for bots 21 | .COMPONENT 22 | PoshGram 23 | #> 24 | function Test-FileSize { 25 | [CmdletBinding()] 26 | param ( 27 | [Parameter(Mandatory = $true, 28 | HelpMessage = 'Path to file')] 29 | [ValidateNotNull()] 30 | [ValidateNotNullOrEmpty()] 31 | [string]$Path 32 | ) 33 | $results = $true #assume the best 34 | $supportedSize = 50 35 | try { 36 | $size = Get-ChildItem -Path $Path -ErrorAction Stop 37 | if (($size.Length / 1MB) -gt $supportedSize) { 38 | Write-Warning -Message "The file is over $supportedSize (MB)" 39 | $results = $false 40 | } 41 | } 42 | catch { 43 | Write-Warning -Message 'An error was encountered evaluating the file size' 44 | $results = $false 45 | } 46 | return $results 47 | } #function_Test-FileSize 48 | -------------------------------------------------------------------------------- /src/PoshGram/Private/Test-MediaGroupRequirements.ps1: -------------------------------------------------------------------------------- 1 | <# 2 | .SYNOPSIS 3 | Verifies that MediaGroup requirements are met. 4 | .DESCRIPTION 5 | Evaluates the provided files to determine if they met all MediaGroup requirements. 6 | .EXAMPLE 7 | Test-MediaGroupRequirements -MediaType Photo -FilePaths $files 8 | 9 | Verifies if the provided files adhere to the Telegram MediaGroup requirements. 10 | .PARAMETER MediaType 11 | Type of media to send 12 | .PARAMETER FilePaths 13 | List of filepaths for media you want to send 14 | .OUTPUTS 15 | System.Boolean 16 | .NOTES 17 | Author: Jake Morrison - @jakemorrison - https://www.techthoughts.info/ 18 | Telegram currently supports a 50MB file size for bots 19 | .COMPONENT 20 | PoshGram 21 | #> 22 | function Test-MediaGroupRequirements { 23 | [CmdletBinding()] 24 | param ( 25 | [Parameter(Mandatory = $true, 26 | HelpMessage = 'Type of media to send')] 27 | [ValidateSet('Photo', 'Video', 'Document', 'Audio')] 28 | [string]$MediaType, 29 | [Parameter(Mandatory = $false, 30 | HelpMessage = 'List of filepaths for media you want to send')] 31 | [ValidateNotNull()] 32 | [ValidateNotNullOrEmpty()] 33 | [string[]]$FilePaths 34 | ) 35 | 36 | Write-Verbose -Message 'Evaluating the group of files for MediaGroup requirements...' 37 | $results = $true #assume the best 38 | 39 | Write-Verbose -Message 'Evaluating file count...' 40 | if ($FilePaths.Count -le 1 -or $FilePaths.Count -gt 10) { 41 | Write-Warning -Message 'Send-TelegramMediaGroup requires a minimum of 2 and a maximum of 10 media files to be provided.' 42 | $results = $false 43 | return $results 44 | } #file_Count 45 | else { 46 | Write-Verbose -Message "File count is: $($FilePaths.Count)" 47 | } #else_FileCount 48 | 49 | foreach ($file in $FilePaths) { 50 | $fileTypeEval = $null 51 | $fileSizeEval = $null 52 | Write-Verbose -Message 'Verifying presence of media...' 53 | if (-not(Test-Path -Path $file)) { 54 | Write-Warning -Message "The specified media path: $file was not found." 55 | $results = $false 56 | return $results 57 | } #if_testPath 58 | if ($MediaType -ne 'Document') { 59 | Write-Verbose -Message 'Verifying extension type...' 60 | $fileTypeEval = Test-FileExtension -FilePath $file -Type $MediaType 61 | if ($fileTypeEval -eq $false) { 62 | $results = $false 63 | return $results 64 | } #if_Extension 65 | else { 66 | Write-Verbose -Message 'Extension supported.' 67 | } #else_Extension 68 | } 69 | Write-Verbose -Message 'Verifying file size...' 70 | $fileSizeEval = Test-FileSize -Path $file 71 | if ($fileSizeEval -eq $false) { 72 | $results = $false 73 | return $results 74 | } #if_Size 75 | else { 76 | Write-Verbose -Message 'File size verified.' 77 | } #else_Size 78 | } #foreach_File 79 | 80 | return $results 81 | 82 | } #Test-MediaGroupRequirements 83 | -------------------------------------------------------------------------------- /src/PoshGram/Private/Test-PollOptions.ps1: -------------------------------------------------------------------------------- 1 | <# 2 | .SYNOPSIS 3 | Verifies that poll options are supported by Telegram 4 | .DESCRIPTION 5 | Evaluates if the provided poll options meet the Telegram poll requirements. 6 | .EXAMPLE 7 | Test-PollOptions -PollOptions $options 8 | 9 | Verifies if the provided options meet the poll requirements. 10 | .EXAMPLE 11 | Test-PollOptions -PollOptions $options 12 | 13 | Verifies if the provided options meet the poll requirements with verbose output. 14 | .PARAMETER PollOptions 15 | Poll Options for eval 16 | .OUTPUTS 17 | System.Boolean 18 | .NOTES 19 | Author: Jake Morrison - @jakemorrison - https://www.techthoughts.info/ 20 | Telegram currently supports 2-10 options 1-100 characters each 21 | .COMPONENT 22 | PoshGram 23 | #> 24 | function Test-PollOptions { 25 | [CmdletBinding()] 26 | param ( 27 | [Parameter(Mandatory = $true, 28 | HelpMessage = 'Poll Options for eval')] 29 | [string[]]$PollOptions 30 | ) 31 | $results = $true #assume the best 32 | Write-Verbose -Message 'Evaluating number of options...' 33 | $optionCount = $PollOptions.Length 34 | if ($optionCount -lt 2 -or $optionCount -gt 10) { 35 | Write-Warning -Message 'Only 2-10 poll options are allowed.' 36 | $results = $false 37 | } #if_optionCount 38 | else { 39 | Write-Verbose -Message 'Option number verified.' 40 | Write-Verbose -Message 'Evaluating character length of options...' 41 | foreach ($option in $PollOptions) { 42 | if ($option.Length -lt 1 -or $option.Length -gt 100) { 43 | Write-Warning -Message "$option is not between 1-100 characters." 44 | $results = $false 45 | } #if_length 46 | } #foreach_option 47 | } #else_optionCount 48 | return $results 49 | } #function_Test-PollOptions 50 | -------------------------------------------------------------------------------- /src/PoshGram/Private/Test-URLExtension.ps1: -------------------------------------------------------------------------------- 1 | <# 2 | .SYNOPSIS 3 | Verifies that specified URL path contains a supported Telegram extension type 4 | .DESCRIPTION 5 | Evaluates the specified URL path to determine if the URL leads to a supported extension type 6 | .EXAMPLE 7 | Test-URLExtension -URL $URL -Type Photo 8 | 9 | Verifies if the URL path specified is a supported photo extension type 10 | .EXAMPLE 11 | Test-URLExtension -URL $PhotoURL -Type Photo -Verbose 12 | 13 | Verifies if the URL path specified is a supported photo extension type with Verbose output 14 | .EXAMPLE 15 | Test-URLExtension -URL $VideoURL -Type Video 16 | 17 | Verifies if the URL path specified is a supported video extension type 18 | .EXAMPLE 19 | Test-URLExtension -URL $AudioURL -Type Audio 20 | 21 | Verifies if the URL path specified is a supported audio extension type 22 | .EXAMPLE 23 | Test-URLExtension -URL $animationURL -Type Animation 24 | 25 | Verifies if the URL path specified is a supported animation extension type 26 | .EXAMPLE 27 | Test-URLExtension -URL $DocumentURL -Type Document 28 | 29 | Verifies if the URL path specified is a supported document extension type 30 | .EXAMPLE 31 | Test-URLExtension -URL $stickerURL -Type Sticker 32 | 33 | Verifies if the URL path specified is a supported sticker extension type 34 | .PARAMETER URL 35 | The URL string to the specified online file 36 | .OUTPUTS 37 | System.Boolean 38 | .NOTES 39 | Author: Jake Morrison - @jakemorrison - https://www.techthoughts.info/ 40 | .COMPONENT 41 | PoshGram 42 | #> 43 | function Test-URLExtension { 44 | [CmdletBinding()] 45 | param ( 46 | [Parameter(Mandatory = $true, 47 | HelpMessage = 'URL string of document')] 48 | [ValidateNotNull()] 49 | [ValidateNotNullOrEmpty()] 50 | [string]$URL, 51 | [Parameter(Mandatory = $true, 52 | HelpMessage = 'Telegram message type')] 53 | [ValidateSet('Photo', 'Video', 'Audio', 'Animation', 'Document', 'Sticker')] 54 | [string]$Type 55 | ) 56 | #------------------------------------------------------------ 57 | $supportedPhotoExtensions = @( 58 | 'JPG' 59 | 'JPEG' 60 | 'PNG' 61 | 'GIF' 62 | 'BMP' 63 | 'WEBP' 64 | 'SVG' 65 | 'TIFF' 66 | ) 67 | $supportedVideoExtensions = @( 68 | 'MP4' 69 | ) 70 | $supportedAudioExtensions = @( 71 | 'MP3' 72 | 'M4A' 73 | ) 74 | $supportedAnimationExtensions = @( 75 | 'GIF' 76 | ) 77 | $supportedDocumentExtensions = @( 78 | 'PDF' 79 | 'GIF' 80 | 'ZIP' 81 | ) 82 | $supportedStickerExtensions = @( 83 | 'WEBP' 84 | 'WEBM' 85 | #'TGS' #* doesn't seem to work for URL uploads 86 | ) 87 | switch ($Type) { 88 | Photo { 89 | $extType = $supportedPhotoExtensions 90 | } #photo 91 | Video { 92 | $extType = $supportedVideoExtensions 93 | } #video 94 | Audio { 95 | $extType = $supportedAudioExtensions 96 | } #audio 97 | Animation { 98 | $extType = $supportedAnimationExtensions 99 | } #animation 100 | Document { 101 | $extType = $supportedDocumentExtensions 102 | } #document 103 | Sticker { 104 | $extType = $supportedStickerExtensions 105 | } #sticker 106 | } #switch_Type 107 | Write-Verbose -Message "Validating type: $Type" 108 | #------------------------------------------------------------ 109 | [bool]$results = $true #assume the best. 110 | #------------------------------------------------------------ 111 | Write-Verbose -Message 'Testing provided URL' 112 | $urlEval = Confirm-URL -Uri $URL 113 | if ($urlEval -ne $true) { 114 | Write-Verbose -Message 'URL Confirmation did not return true.' 115 | $results = $false 116 | return $results 117 | } #if_urlEval 118 | #------------------------------------------------------------ 119 | Write-Verbose -Message 'Resolving potential shortlink...' 120 | $slEval = Resolve-ShortLink -Uri $URL -ErrorAction SilentlyContinue 121 | if ($slEval) { 122 | $URL = $slEval 123 | } #if_slEval 124 | #------------------------------------------------------------ 125 | Write-Verbose -Message "Processing $URL ..." 126 | $divide = $URL.Split('.') 127 | $rawExtension = $divide[$divide.Length - 1] 128 | $extension = $rawExtension.ToUpper() 129 | Write-Verbose -Message "Verifying discovered extension: $extension" 130 | switch ($extension) { 131 | { $extType -contains $_ } { 132 | Write-Verbose -Message 'Extension verified.' 133 | } 134 | default { 135 | Write-Warning -Message "The specified file is not a supported $Type extension." 136 | $results = $false 137 | } #default 138 | } #switch_extension 139 | #------------------------------------------------------------ 140 | return $results 141 | } #function_Test-URLExtension 142 | -------------------------------------------------------------------------------- /src/PoshGram/Private/Test-URLFileSize.ps1: -------------------------------------------------------------------------------- 1 | <# 2 | .SYNOPSIS 3 | Verifies that specified URL file size is supported by Telegram 4 | .DESCRIPTION 5 | Evaluates the specified URL path to determine if the file is at or below the supported Telegram file size 6 | .EXAMPLE 7 | Test-URLFileSize -URL 'https://github.com/techthoughts2/PoshGram/raw/main/test/SourceFiles/techthoughts.png' 8 | 9 | Verifies if the file in the specified URL is at or below the Telegram maximum size 10 | .EXAMPLE 11 | Test-URLFileSize -URL $URL -Verbose 12 | 13 | Verifies if the file in the specified URL is at or below the Telegram maximum size with verbose output 14 | .PARAMETER URL 15 | URL address to file 16 | .OUTPUTS 17 | System.Boolean 18 | .NOTES 19 | Author: Jake Morrison - @jakemorrison - https://www.techthoughts.info/ 20 | Telegram currently supports a 50MB file size for bots 21 | .COMPONENT 22 | PoshGram 23 | #> 24 | function Test-URLFileSize { 25 | [CmdletBinding()] 26 | param ( 27 | [Parameter(Mandatory = $true, 28 | HelpMessage = 'URL address to file')] 29 | [ValidateNotNull()] 30 | [ValidateNotNullOrEmpty()] 31 | [string]$URL 32 | ) 33 | $results = $true #assume the best 34 | $supportedSize = 50 35 | try { 36 | $urlFileInfo = Invoke-WebRequest $URL -ErrorAction Stop 37 | if (($urlFileInfo.RawContentLength / 1MB) -gt $supportedSize) { 38 | Write-Warning -Message "The file is over $supportedSize (MB)" 39 | $results = $false 40 | } #if_size 41 | } #try_Invoke-WebRequest 42 | catch { 43 | Write-Warning -Message 'An error was encountered evaluating the file size' 44 | $results = $false 45 | } #catch_Invoke-WebRequest 46 | return $results 47 | } #function_Test-URLFileSize 48 | -------------------------------------------------------------------------------- /src/PoshGram/Public/Get-TelegramCustomEmojiStickerInfo.ps1: -------------------------------------------------------------------------------- 1 | <# 2 | .SYNOPSIS 3 | Retrieve information about Telegram custom emoji stickers using their identifiers. 4 | .DESCRIPTION 5 | This function interacts with the Telegram Bot API to gather detailed information about custom emoji stickers 6 | specified by their unique identifiers. It can handle requests for up to 200 custom emoji IDs at a time 7 | .EXAMPLE 8 | $botToken = 'nnnnnnnnn:xxxxxxx-xxxxxxxxxxxxxxxxxxxxxxxxxxx' 9 | Get-TelegramCustomEmojiStickerInfo -BotToken $botToken -CustomEmojiIdentifier 5404870433939922908 10 | 11 | Retrieves detailed information about the custom emoji sticker with identifier 5404870433939922908. 12 | .EXAMPLE 13 | $botToken = 'nnnnnnnnn:xxxxxxx-xxxxxxxxxxxxxxxxxxxxxxxxxxx' 14 | Get-TelegramCustomEmojiStickerInfo -BotToken $botToken -CustomEmojiIdentifier 5404870433939922908, 5368324170671202286 15 | 16 | Fetches information for multiple custom emoji stickers, using their respective identifiers 5404870433939922908 and 5368324170671202286. 17 | .PARAMETER BotToken 18 | Use this token to access the HTTP API 19 | .PARAMETER CustomEmojiIdentifier 20 | Custom emoji ID number(s). Specify up to 200 custom emoji IDs. 21 | .OUTPUTS 22 | System.Management.Automation.PSCustomObject 23 | .NOTES 24 | Author: Jake Morrison - @jakemorrison - https://www.techthoughts.info/ 25 | 26 | Questions on how to set up a bot, get a token, or get your channel ID? 27 | Answers on the PoshGram documentation: https://poshgram.readthedocs.io/en/latest/PoshGram-FAQ/ 28 | 29 | Note: 30 | - This function is currently experimental. Bots can only access custom emoji sticker information for purchased additional usernames on Fragment. 31 | - This makes it difficult to determine the custom emoji ID for a custom emoji sticker pack. 32 | - pwshEmojiExplorer is used to retrieve additional emoji information. 33 | .COMPONENT 34 | PoshGram 35 | .FUNCTIONALITY 36 | Parameter Type Required Description 37 | custom_emoji_ids Array of String Yes List of custom emoji identifiers. At most 200 custom emoji identifiers can be specified. 38 | .LINK 39 | https://poshgram.readthedocs.io/en/latest/Get-TelegramCustomEmojiStickerInfo 40 | .LINK 41 | https://poshgram.readthedocs.io/en/doctesting/PoshGram-Sticker-Info/ 42 | .LINK 43 | https://core.telegram.org/bots/api#getcustomemojistickers 44 | .LINK 45 | https://core.telegram.org/bots/api#sticker 46 | .LINK 47 | https://core.telegram.org/bots/api 48 | #> 49 | function Get-TelegramCustomEmojiStickerInfo { 50 | [CmdletBinding()] 51 | param ( 52 | [Parameter(Mandatory = $true, 53 | HelpMessage = '#########:xxxxxxx-xxxxxxxxxxxxxxxxxxxxxxxxxxx')] 54 | [ValidateNotNull()] 55 | [ValidateNotNullOrEmpty()] 56 | [string]$BotToken, #you could set a token right here if you wanted 57 | 58 | [Parameter(Mandatory = $true, 59 | HelpMessage = 'Custom Emoji pack name')] 60 | [ValidateNotNullOrEmpty()] 61 | [ValidateCount(1, 200)] 62 | [string[]]$CustomEmojiIdentifier 63 | ) 64 | 65 | Write-Verbose -Message ('Starting: {0}' -f $MyInvocation.Mycommand) 66 | 67 | Write-Debug -Message ('Identifier count: {0}' -f $CustomEmojiIdentifier.Count) 68 | 69 | $identifierList = New-Object System.Collections.Generic.List[string] 70 | foreach ($identifier in $CustomEmojiIdentifier) { 71 | [void]$identifierList.Add($identifier) 72 | } 73 | 74 | if ($identifierList.Count -eq 1) { 75 | # special case for single identifier where we have to hand-craft the JSON 76 | $jsonIdentifierArray = @" 77 | [ 78 | "$identifierList" 79 | ] 80 | "@ 81 | } #if 82 | else { 83 | $jsonIdentifierArray = $identifierList | ConvertTo-Json 84 | } #else 85 | 86 | $form = @{ 87 | custom_emoji_ids = $jsonIdentifierArray 88 | } #form 89 | 90 | $uri = 'https://api.telegram.org/bot{0}/getCustomEmojiStickers' -f $BotToken 91 | Write-Debug -Message ('Base URI: {0}' -f $uri) 92 | 93 | Write-Verbose -Message 'Retrieving sticker information...' 94 | $invokeRestMethodSplat = @{ 95 | Uri = $uri 96 | ErrorAction = 'Stop' 97 | Form = $form 98 | Method = 'Post' 99 | } 100 | try { 101 | $results = Invoke-RestMethod @invokeRestMethodSplat 102 | } #try_messageSend 103 | catch { 104 | Write-Warning -Message 'An error was encountered getting the Telegram custom emoji pack info:' 105 | if ($_.ErrorDetails) { 106 | $results = $_.ErrorDetails | ConvertFrom-Json -ErrorAction SilentlyContinue 107 | return $results 108 | } 109 | else { 110 | throw $_ 111 | } 112 | } #catch_messageSend 113 | 114 | # Add-EmojiDetails 115 | 116 | Write-Verbose -Message 'Custom emoji information found. Processing emoji information...' 117 | $stickerData = New-Object System.Collections.Generic.List[Object] 118 | foreach ($emoji in $results.result) { 119 | #------------------- 120 | $enrichedEmoji = $null 121 | #------------------- 122 | $enrichedEmoji = Add-EmojiDetail -StickerObject $emoji 123 | [void]$stickerData.Add($enrichedEmoji) 124 | } 125 | 126 | return $stickerData 127 | } #function_Get-TelegramCustomEmojiStickerInfo 128 | -------------------------------------------------------------------------------- /src/PoshGram/Public/Get-TelegramStickerPackInfo.ps1: -------------------------------------------------------------------------------- 1 | <# 2 | .SYNOPSIS 3 | Retrieve detailed information about a specified Telegram sticker pack. 4 | .DESCRIPTION 5 | This function connects to the Telegram Bot API to fetch detailed information about a specified sticker pack. 6 | It is designed to help you explore the contents of a Telegram sticker pack by providing a variety of information for each sticker. 7 | This includes details like the associated emoji, its group and subgroup classifications, Unicode code, shortcode, and the sticker's file ID. 8 | It also leverages the capabilities of pwshEmojiExplorer to retrieve additional emoji information, enriching the data set provided. 9 | To effectively use this function, you need the name of the sticker pack. You can find this by sharing the sticker pack within the Telegram app, which will generate a link containing the pack's name. 10 | More information is available in the links. 11 | .EXAMPLE 12 | $botToken = 'nnnnnnnnn:xxxxxxx-xxxxxxxxxxxxxxxxxxxxxxxxxxx' 13 | Get-TelegramStickerPackInfo -BotToken $botToken -StickerSetName STPicard 14 | 15 | Retrieves information for the STPicard sticker pack from the Telegram Bot API. 16 | .EXAMPLE 17 | $botToken = 'nnnnnnnnn:xxxxxxx-xxxxxxxxxxxxxxxxxxxxxxxxxxx' 18 | Get-TelegramStickerPackInfo -BotToken $botToken -StickerSetName FriendlyFelines 19 | 20 | Retrieves information for the FriendlyFelines sticker pack from the Telegram Bot API. 21 | .PARAMETER BotToken 22 | Use this token to access the HTTP API 23 | .PARAMETER StickerSetName 24 | Name of the sticker set 25 | .OUTPUTS 26 | System.Management.Automation.PSCustomObject 27 | .NOTES 28 | Author: Jake Morrison - @jakemorrison - https://www.techthoughts.info/ 29 | 30 | Questions on how to set up a bot, get a token, or get your channel ID? 31 | Answers on the PoshGram documentation: https://poshgram.readthedocs.io/en/latest/PoshGram-FAQ/ 32 | 33 | Note: 34 | - Some sticker authors use the same emoji for several of their stickers. 35 | - pwshEmojiExplorer is used to retrieve additional emoji information. 36 | .COMPONENT 37 | PoshGram 38 | .FUNCTIONALITY 39 | Parameter Type Required Description 40 | name String Yes Name of the sticker set 41 | .LINK 42 | https://poshgram.readthedocs.io/en/latest/Get-TelegramStickerPackInfo 43 | .LINK 44 | https://poshgram.readthedocs.io/en/doctesting/PoshGram-Sticker-Info/ 45 | .LINK 46 | https://core.telegram.org/bots/api#getstickerset 47 | .LINK 48 | https://core.telegram.org/bots/api#sticker 49 | .LINK 50 | https://core.telegram.org/bots/api 51 | #> 52 | function Get-TelegramStickerPackInfo { 53 | [CmdletBinding()] 54 | param ( 55 | [Parameter(Mandatory = $true, 56 | HelpMessage = '#########:xxxxxxx-xxxxxxxxxxxxxxxxxxxxxxxxxxx')] 57 | [ValidateNotNull()] 58 | [ValidateNotNullOrEmpty()] 59 | [string]$BotToken, #you could set a token right here if you wanted 60 | 61 | [Parameter(Mandatory = $true, 62 | HelpMessage = 'Sticker pack name')] 63 | [ValidateNotNullOrEmpty()] 64 | [string]$StickerSetName 65 | ) 66 | 67 | Write-Verbose -Message ('Starting: {0}' -f $MyInvocation.Mycommand) 68 | 69 | $form = @{ 70 | name = $StickerSetName 71 | } #form 72 | 73 | $uri = 'https://api.telegram.org/bot{0}/getStickerSet' -f $BotToken 74 | Write-Debug -Message ('Base URI: {0}' -f $uri) 75 | 76 | Write-Verbose -Message 'Retrieving sticker information...' 77 | $invokeRestMethodSplat = @{ 78 | Uri = $uri 79 | ErrorAction = 'Stop' 80 | Form = $form 81 | Method = 'Post' 82 | } 83 | try { 84 | $results = Invoke-RestMethod @invokeRestMethodSplat 85 | } #try_messageSend 86 | catch { 87 | Write-Warning -Message 'An error was encountered getting the Telegram sticker info:' 88 | if ($_.ErrorDetails) { 89 | $results = $_.ErrorDetails | ConvertFrom-Json -ErrorAction SilentlyContinue 90 | return $results 91 | } 92 | else { 93 | throw $_ 94 | } 95 | } #catch_messageSend 96 | 97 | Write-Verbose -Message 'Sticker information found. Processing emoji information...' 98 | $stickerData = New-Object System.Collections.Generic.List[Object] 99 | foreach ($emoji in $results.result.stickers) { 100 | #------------------- 101 | $enrichedEmoji = $null 102 | #------------------- 103 | $enrichedEmoji = Add-EmojiDetail -StickerObject $emoji 104 | [void]$stickerData.Add($enrichedEmoji) 105 | } 106 | 107 | return $stickerData 108 | } #function_Get-TelegramStickerPackInfo 109 | -------------------------------------------------------------------------------- /src/PoshGram/Public/Send-TelegramContact.ps1: -------------------------------------------------------------------------------- 1 | <# 2 | .SYNOPSIS 3 | Sends Telegram phone contact message via BOT API. 4 | .DESCRIPTION 5 | Uses Telegram Bot API to send contact information to specified Telegram chat. 6 | .EXAMPLE 7 | $botToken = 'nnnnnnnnn:xxxxxxx-xxxxxxxxxxxxxxxxxxxxxxxxxxx' 8 | $chatID = '-nnnnnnnnn' 9 | $phone = '1-222-222-2222' 10 | $firstName = 'Jean-Luc' 11 | Send-TelegramContact -BotToken $botToken -ChatID $chatID -PhoneNumber $phone -FirstName $firstName 12 | 13 | Sends contact via Telegram API 14 | .EXAMPLE 15 | $botToken = 'nnnnnnnnn:xxxxxxx-xxxxxxxxxxxxxxxxxxxxxxxxxxx' 16 | $chatID = '-nnnnnnnnn' 17 | $phone = '1-222-222-2222' 18 | $firstName = 'Jean-Luc' 19 | $lastName = 'Picard' 20 | $sendTelegramContactSplat = @{ 21 | BotToken = $botToken 22 | ChatID = $chatID 23 | PhoneNumber = $phone 24 | FirstName = $firstName 25 | LastName = $lastName 26 | DisableNotification = $true 27 | ProtectContent = $true 28 | Verbose = $true 29 | } 30 | Send-TelegramContact @sendTelegramContactSplat 31 | 32 | Sends contact via Telegram API 33 | .PARAMETER BotToken 34 | Use this token to access the HTTP API 35 | .PARAMETER ChatID 36 | Unique identifier for the target chat 37 | .PARAMETER PhoneNumber 38 | Contact phone number 39 | .PARAMETER FirstName 40 | Contact first name 41 | .PARAMETER LastName 42 | Contact last name 43 | .PARAMETER DisableNotification 44 | Send the message silently. Users will receive a notification with no sound. 45 | .PARAMETER ProtectContent 46 | Protects the contents of the sent message from forwarding and saving 47 | .OUTPUTS 48 | System.Management.Automation.PSCustomObject 49 | .NOTES 50 | Author: Jake Morrison - @jakemorrison - https://www.techthoughts.info/ 51 | 52 | Questions on how to set up a bot, get a token, or get your channel ID? 53 | Answers on the PoshGram documentation: https://poshgram.readthedocs.io/en/latest/PoshGram-FAQ/ 54 | .COMPONENT 55 | PoshGram 56 | .FUNCTIONALITY 57 | Parameter Type Required Description 58 | chat_id Integer or String Yes Unique identifier for the target chat or username of the target channel (in the format @channelusername) 59 | phone_number String Yes Contact's phone number 60 | first_name String Yes Contact's first name 61 | last_name String Optional Contact's last name 62 | .LINK 63 | https://poshgram.readthedocs.io/en/latest/Send-TelegramContact 64 | .LINK 65 | https://core.telegram.org/bots/api#sendcontact 66 | .LINK 67 | https://core.telegram.org/bots/api 68 | #> 69 | function Send-TelegramContact { 70 | [CmdletBinding()] 71 | param ( 72 | [Parameter(Mandatory = $true, 73 | HelpMessage = '#########:xxxxxxx-xxxxxxxxxxxxxxxxxxxxxxxxxxx')] 74 | [ValidateNotNull()] 75 | [ValidateNotNullOrEmpty()] 76 | [string]$BotToken, #you could set a token right here if you wanted 77 | 78 | [Parameter(Mandatory = $true, 79 | HelpMessage = '-#########')] 80 | [ValidateNotNull()] 81 | [ValidateNotNullOrEmpty()] 82 | [string]$ChatID, #you could set a Chat ID right here if you wanted 83 | 84 | [Parameter(Mandatory = $true, 85 | HelpMessage = 'Contact phone number')] 86 | [ValidateNotNullOrEmpty()] 87 | [string]$PhoneNumber, 88 | 89 | [Parameter(Mandatory = $true, 90 | HelpMessage = 'Contact first name')] 91 | [ValidateNotNullOrEmpty()] 92 | [string]$FirstName, 93 | 94 | [Parameter(Mandatory = $false, 95 | HelpMessage = 'Contact last name')] 96 | [ValidateNotNullOrEmpty()] 97 | [string]$LastName, 98 | 99 | [Parameter(Mandatory = $false, 100 | HelpMessage = 'Send the message silently')] 101 | [switch]$DisableNotification, 102 | 103 | [Parameter(Mandatory = $false, 104 | HelpMessage = 'Protects the contents of the sent message from forwarding and saving')] 105 | [switch]$ProtectContent 106 | ) 107 | 108 | Write-Verbose -Message ('Starting: {0}' -f $MyInvocation.Mycommand) 109 | 110 | $form = @{ 111 | chat_id = $ChatID 112 | phone_number = $PhoneNumber 113 | first_name = $FirstName 114 | last_name = $LastName 115 | disable_notification = $DisableNotification.IsPresent 116 | protect_content = $ProtectContent.IsPresent 117 | } #form 118 | 119 | $uri = 'https://api.telegram.org/bot{0}/sendContact' -f $BotToken 120 | Write-Debug -Message ('Base URI: {0}' -f $uri) 121 | 122 | Write-Verbose -Message 'Sending contact...' 123 | $invokeRestMethodSplat = @{ 124 | Uri = $uri 125 | ErrorAction = 'Stop' 126 | Form = $form 127 | Method = 'Post' 128 | } 129 | try { 130 | $results = Invoke-RestMethod @invokeRestMethodSplat 131 | } #try_messageSend 132 | catch { 133 | Write-Warning -Message 'An error was encountered sending the Telegram contact:' 134 | if ($_.ErrorDetails) { 135 | $results = $_.ErrorDetails | ConvertFrom-Json -ErrorAction SilentlyContinue 136 | } 137 | else { 138 | throw $_ 139 | } 140 | } #catch_messageSend 141 | 142 | return $results 143 | } #function_Send-TelegramContact 144 | -------------------------------------------------------------------------------- /src/PoshGram/Public/Send-TelegramDice.ps1: -------------------------------------------------------------------------------- 1 | <# 2 | .SYNOPSIS 3 | Sends Telegram animated emoji that will display a random value. 4 | .DESCRIPTION 5 | Uses Telegram Bot API to send animated emoji that will display a random value to specified Telegram chat. 6 | .EXAMPLE 7 | $botToken = 'nnnnnnnnn:xxxxxxx-xxxxxxxxxxxxxxxxxxxxxxxxxxx' 8 | $chatID = '-nnnnnnnnn' 9 | $emoji = 'basketball' 10 | Send-TelegramDice -BotToken $botToken -ChatID $chatID -Emoji $emoji 11 | 12 | Sends animated basketball emoji that displays a random value via Telegram API 13 | .EXAMPLE 14 | $botToken = 'nnnnnnnnn:xxxxxxx-xxxxxxxxxxxxxxxxxxxxxxxxxxx' 15 | $chatID = '-nnnnnnnnn' 16 | $emoji = 'dice' 17 | $sendTelegramDiceSplat = @{ 18 | BotToken = $botToken 19 | ChatID = $chatID 20 | DisableNotification = $true 21 | ProtectContent = $true 22 | Verbose = $true 23 | Emoji = $emoji 24 | } 25 | Send-TelegramDice @sendTelegramDiceSplat 26 | 27 | Sends animated dice emoji that displays a random value via Telegram API 28 | .PARAMETER BotToken 29 | Use this token to access the HTTP API 30 | .PARAMETER ChatID 31 | Unique identifier for the target chat 32 | .PARAMETER Emoji 33 | Emoji on which the dice throw animation is based. 34 | .PARAMETER DisableNotification 35 | Send the message silently. Users will receive a notification with no sound. 36 | .PARAMETER ProtectContent 37 | Protects the contents of the sent message from forwarding and saving 38 | .OUTPUTS 39 | System.Management.Automation.PSCustomObject 40 | .NOTES 41 | Author: Jake Morrison - @jakemorrison - https://www.techthoughts.info/ 42 | 43 | Questions on how to set up a bot, get a token, or get your channel ID? 44 | Answers on the PoshGram documentation: https://poshgram.readthedocs.io/en/latest/PoshGram-FAQ/ 45 | .COMPONENT 46 | PoshGram 47 | .FUNCTIONALITY 48 | Parameters Type Required Description 49 | chat_id Integer or String Yes Unique identifier for the target chat or username of the target channel (in the format @channelusername) 50 | emoji String Optional Emoji on which the dice throw animation is based. Currently, must be one of “🎲”, “🎯”, or “🏀”. Dice can have values 1-6 for “🎲” and “🎯”, and values 1-5 for “🏀”. Defaults to “🎲” 51 | disable_notification Boolean Optional Sends the message silently. Users will receive a notification with no sound. 52 | .LINK 53 | https://poshgram.readthedocs.io/en/latest/Send-TelegramDice 54 | .LINK 55 | https://core.telegram.org/bots/api#senddice 56 | .LINK 57 | https://core.telegram.org/bots/api 58 | #> 59 | function Send-TelegramDice { 60 | [CmdletBinding()] 61 | param ( 62 | [Parameter(Mandatory = $true, 63 | HelpMessage = '#########:xxxxxxx-xxxxxxxxxxxxxxxxxxxxxxxxxxx')] 64 | [ValidateNotNull()] 65 | [ValidateNotNullOrEmpty()] 66 | [string]$BotToken, #you could set a token right here if you wanted 67 | 68 | [Parameter(Mandatory = $true, 69 | HelpMessage = '-#########')] 70 | [ValidateNotNull()] 71 | [ValidateNotNullOrEmpty()] 72 | [string]$ChatID, #you could set a Chat ID right here if you wanted 73 | 74 | [Parameter(Mandatory = $true, 75 | HelpMessage = 'Emoji on which the dice throw animation is based.')] 76 | [ValidateSet('dice', 'dart', 'basketball', 'football', 'slotmachine', 'bowling')] 77 | [string]$Emoji, 78 | 79 | [Parameter(Mandatory = $false, 80 | HelpMessage = 'Send the message silently')] 81 | [switch]$DisableNotification, 82 | 83 | [Parameter(Mandatory = $false, 84 | HelpMessage = 'Protects the contents of the sent message from forwarding and saving')] 85 | [switch]$ProtectContent 86 | ) 87 | 88 | Write-Verbose -Message ('Starting: {0}' -f $MyInvocation.Mycommand) 89 | 90 | switch ($Emoji) { 91 | dice { 92 | $emojiSend = '🎲' 93 | } 94 | dart { 95 | $emojiSend = '🎯' 96 | } 97 | basketball { 98 | $emojiSend = '🏀' 99 | } 100 | football { 101 | $emojiSend = '⚽' 102 | } 103 | slotmachine { 104 | $emojiSend = '🎰' 105 | } 106 | bowling { 107 | $emojiSend = '🎳' 108 | } 109 | } 110 | 111 | $form = @{ 112 | chat_id = $ChatID 113 | emoji = $emojiSend 114 | disable_notification = $DisableNotification.IsPresent 115 | protect_content = $ProtectContent.IsPresent 116 | } #form 117 | 118 | $uri = 'https://api.telegram.org/bot{0}/sendDice' -f $BotToken 119 | Write-Debug -Message ('Base URI: {0}' -f $uri) 120 | 121 | Write-Verbose -Message 'Sending dice...' 122 | $invokeRestMethodSplat = @{ 123 | Uri = $uri 124 | ErrorAction = 'Stop' 125 | Form = $form 126 | Method = 'Post' 127 | } 128 | try { 129 | $results = Invoke-RestMethod @invokeRestMethodSplat 130 | } #try_messageSend 131 | catch { 132 | Write-Warning -Message 'An error was encountered sending the Telegram location:' 133 | Write-Error $_ 134 | if ($_.ErrorDetails) { 135 | $results = $_.ErrorDetails | ConvertFrom-Json -ErrorAction SilentlyContinue 136 | } 137 | else { 138 | throw $_ 139 | } 140 | } #catch_messageSend 141 | 142 | return $results 143 | } #function_Send-TelegramDice 144 | -------------------------------------------------------------------------------- /src/PoshGram/Public/Send-TelegramLocation.ps1: -------------------------------------------------------------------------------- 1 | <# 2 | .SYNOPSIS 3 | Sends Telegram location to indicate point on map 4 | .DESCRIPTION 5 | Uses Telegram Bot API to send latitude and longitude points on map to specified Telegram chat. 6 | .EXAMPLE 7 | $botToken = 'nnnnnnnnn:xxxxxxx-xxxxxxxxxxxxxxxxxxxxxxxxxxx' 8 | $chatID = '-nnnnnnnnn' 9 | $latitude = 37.621313 10 | $longitude = -122.378955 11 | Send-TelegramLocation -BotToken $botToken -ChatID $chatID -Latitude $latitude -Longitude $longitude 12 | 13 | Sends location via Telegram API 14 | .EXAMPLE 15 | $botToken = 'nnnnnnnnn:xxxxxxx-xxxxxxxxxxxxxxxxxxxxxxxxxxx' 16 | $chatID = '-nnnnnnnnn' 17 | $sendTelegramLocationSplat = @{ 18 | BotToken = $botToken 19 | ChatID = $chatID 20 | Latitude = $latitude 21 | Longitude = $longitude 22 | DisableNotification = $true 23 | ProtectContent = $true 24 | Verbose = $true 25 | } 26 | Send-TelegramLocation @sendTelegramLocationSplat 27 | 28 | Sends location via Telegram API 29 | .PARAMETER BotToken 30 | Use this token to access the HTTP API 31 | .PARAMETER ChatID 32 | Unique identifier for the target chat 33 | .PARAMETER Latitude 34 | Latitude of the location 35 | .PARAMETER Longitude 36 | Longitude of the location 37 | .PARAMETER DisableNotification 38 | Send the message silently. Users will receive a notification with no sound. 39 | .PARAMETER ProtectContent 40 | Protects the contents of the sent message from forwarding and saving 41 | .OUTPUTS 42 | System.Management.Automation.PSCustomObject 43 | .NOTES 44 | Author: Jake Morrison - @jakemorrison - https://www.techthoughts.info/ 45 | 46 | Questions on how to set up a bot, get a token, or get your channel ID? 47 | Answers on the PoshGram documentation: https://poshgram.readthedocs.io/en/latest/PoshGram-FAQ/ 48 | .COMPONENT 49 | PoshGram 50 | .FUNCTIONALITY 51 | Parameters Type Required Description 52 | chat_id Integer or String Yes Unique identifier for the target chat or username of the target channel (in the format @channelusername) 53 | latitude Float number Yes Latitude of the location 54 | longitude Float number Yes Longitude of the location 55 | disable_notification Boolean Optional Sends the message silently. Users will receive a notification with no sound. 56 | .LINK 57 | https://poshgram.readthedocs.io/en/latest/Send-TelegramLocation 58 | .LINK 59 | https://core.telegram.org/bots/api#sendlocation 60 | .LINK 61 | https://core.telegram.org/bots/api 62 | #> 63 | function Send-TelegramLocation { 64 | [CmdletBinding()] 65 | param ( 66 | [Parameter(Mandatory = $true, 67 | HelpMessage = '#########:xxxxxxx-xxxxxxxxxxxxxxxxxxxxxxxxxxx')] 68 | [ValidateNotNull()] 69 | [ValidateNotNullOrEmpty()] 70 | [string]$BotToken, #you could set a token right here if you wanted 71 | 72 | [Parameter(Mandatory = $true, 73 | HelpMessage = '-#########')] 74 | [ValidateNotNull()] 75 | [ValidateNotNullOrEmpty()] 76 | [string]$ChatID, #you could set a Chat ID right here if you wanted 77 | 78 | [Parameter(Mandatory = $true, 79 | HelpMessage = 'Latitude of the location')] 80 | [ValidateRange(-90, 90)] 81 | [single]$Latitude, 82 | 83 | [Parameter(Mandatory = $true, 84 | HelpMessage = 'Longitude of the location')] 85 | [ValidateRange(-180, 180)] 86 | [single]$Longitude, 87 | 88 | [Parameter(Mandatory = $false, 89 | HelpMessage = 'Send the message silently')] 90 | [switch]$DisableNotification, 91 | 92 | [Parameter(Mandatory = $false, 93 | HelpMessage = 'Protects the contents of the sent message from forwarding and saving')] 94 | [switch]$ProtectContent 95 | ) 96 | 97 | Write-Verbose -Message ('Starting: {0}' -f $MyInvocation.Mycommand) 98 | 99 | $form = @{ 100 | chat_id = $ChatID 101 | latitude = $Latitude 102 | longitude = $Longitude 103 | disable_notification = $DisableNotification.IsPresent 104 | protect_content = $ProtectContent.IsPresent 105 | } #form 106 | 107 | $uri = 'https://api.telegram.org/bot{0}/sendLocation' -f $BotToken 108 | Write-Debug -Message ('Base URI: {0}' -f $uri) 109 | 110 | Write-Verbose -Message 'Sending location...' 111 | $invokeRestMethodSplat = @{ 112 | Uri = $uri 113 | ErrorAction = 'Stop' 114 | Form = $form 115 | Method = 'Post' 116 | } 117 | try { 118 | $results = Invoke-RestMethod @invokeRestMethodSplat 119 | } #try_messageSend 120 | catch { 121 | Write-Warning -Message 'An error was encountered sending the Telegram location:' 122 | Write-Error $_ 123 | if ($_.ErrorDetails) { 124 | $results = $_.ErrorDetails | ConvertFrom-Json -ErrorAction SilentlyContinue 125 | } 126 | else { 127 | throw $_ 128 | } 129 | } #catch_messageSend 130 | 131 | return $results 132 | } #function_Send-TelegramLocation 133 | -------------------------------------------------------------------------------- /src/PoshGram/Public/Send-TelegramURLSticker.ps1: -------------------------------------------------------------------------------- 1 | <# 2 | .SYNOPSIS 3 | Sends Telegram sticker message via Bot API from URL sourced sticker image 4 | .DESCRIPTION 5 | Uses Telegram Bot API to send sticker message to specified Telegram chat. The sticker will be sourced from the provided URL and sent to Telegram. 6 | .EXAMPLE 7 | $botToken = 'nnnnnnnnn:xxxxxxx-xxxxxxxxxxxxxxxxxxxxxxxxxxx' 8 | $chatID = '-nnnnnnnnn' 9 | $stickerURL = 'https://github.com/techthoughts2/PoshGram/raw/main/test/SourceFiles/techthoughts.webp' 10 | Send-TelegramURLSticker -BotToken $botToken -ChatID $chatID -StickerURL $stickerURL 11 | 12 | Sends sticker message via Telegram API 13 | .EXAMPLE 14 | $botToken = 'nnnnnnnnn:xxxxxxx-xxxxxxxxxxxxxxxxxxxxxxxxxxx' 15 | $chatID = '-nnnnnnnnn' 16 | $stickerURL = 'https://github.com/techthoughts2/PoshGram/raw/main/test/SourceFiles/techthoughts.webp' 17 | $sendTelegramURLStickerSplat = @{ 18 | BotToken = $botToken 19 | ChatID = $chatID 20 | StickerURL = $stickerURL 21 | DisableNotification = $true 22 | ProtectContent = $true 23 | Verbose = $true 24 | } 25 | Send-TelegramURLSticker @sendTelegramURLStickerSplat 26 | 27 | Sends sticker message via Telegram API 28 | .PARAMETER BotToken 29 | Use this token to access the HTTP API 30 | .PARAMETER ChatID 31 | Unique identifier for the target chat 32 | .PARAMETER StickerURL 33 | URL path to sticker 34 | .PARAMETER DisableNotification 35 | Send the message silently. Users will receive a notification with no sound. 36 | .PARAMETER ProtectContent 37 | Protects the contents of the sent message from forwarding and saving 38 | .OUTPUTS 39 | System.Management.Automation.PSCustomObject 40 | .NOTES 41 | Author: Jake Morrison - @jakemorrison - https://www.techthoughts.info/ 42 | 43 | The following sticker types are supported: 44 | WEBP, WEBM 45 | 46 | Questions on how to set up a bot, get a token, or get your channel ID? 47 | Answers on the PoshGram documentation: https://poshgram.readthedocs.io/en/latest/PoshGram-FAQ/ 48 | .COMPONENT 49 | PoshGram 50 | .FUNCTIONALITY 51 | Parameters Type Required Description 52 | chat_id Integer or String Yes Unique identifier for the target chat or username of the target channel (in the format @channelusername) 53 | sticker InputFile or String Yes Sticker to send. 54 | disable_notification Boolean Optional Sends the message silently. Users will receive a notification with no sound. 55 | .LINK 56 | https://poshgram.readthedocs.io/en/latest/Send-TelegramURLSticker 57 | .LINK 58 | https://core.telegram.org/bots/api#sendsticker 59 | .LINK 60 | https://core.telegram.org/bots/api 61 | #> 62 | function Send-TelegramURLSticker { 63 | [CmdletBinding()] 64 | param ( 65 | [Parameter(Mandatory = $true, 66 | HelpMessage = '#########:xxxxxxx-xxxxxxxxxxxxxxxxxxxxxxxxxxx')] 67 | [ValidateNotNull()] 68 | [ValidateNotNullOrEmpty()] 69 | [string]$BotToken, #you could set a token right here if you wanted 70 | 71 | [Parameter(Mandatory = $true, 72 | HelpMessage = '-#########')] 73 | [ValidateNotNull()] 74 | [ValidateNotNullOrEmpty()] 75 | [string]$ChatID, #you could set a Chat ID right here if you wanted 76 | 77 | [Parameter(Mandatory = $true, 78 | HelpMessage = 'URL path to sticker')] 79 | [ValidateNotNull()] 80 | [ValidateNotNullOrEmpty()] 81 | [string]$StickerURL, 82 | 83 | [Parameter(Mandatory = $false, 84 | HelpMessage = 'Send the message silently')] 85 | [switch]$DisableNotification, 86 | 87 | [Parameter(Mandatory = $false, 88 | HelpMessage = 'Protects the contents of the sent message from forwarding and saving')] 89 | [switch]$ProtectContent 90 | ) 91 | 92 | Write-Verbose -Message ('Starting: {0}' -f $MyInvocation.Mycommand) 93 | 94 | Write-Verbose -Message 'Verifying URL leads to supported sticker extension...' 95 | $fileTypeEval = Test-URLExtension -URL $StickerURL -Type Sticker 96 | if ($fileTypeEval -eq $false) { 97 | throw ('The specified sticker URL: {0} does not contain a supported extension.' -f $StickerURL) 98 | } #if_stickerExtension 99 | else { 100 | Write-Verbose -Message 'Extension supported.' 101 | } #else_stickerExtension 102 | 103 | Write-Verbose -Message 'Verifying URL presence and file size...' 104 | $fileSizeEval = Test-URLFileSize -URL $StickerURL 105 | if ($fileSizeEval -eq $false) { 106 | throw 'File size does not meet Telegram requirements' 107 | } #if_stickerSize 108 | else { 109 | Write-Verbose -Message 'File size verified.' 110 | } #else_stickerSize 111 | 112 | $payload = @{ 113 | chat_id = $ChatID 114 | sticker = $StickerURL 115 | disable_notification = $DisableNotification.IsPresent 116 | protect_content = $ProtectContent.IsPresent 117 | } #payload 118 | 119 | $uri = 'https://api.telegram.org/bot{0}/sendSticker' -f $BotToken 120 | Write-Debug -Message ('Base URI: {0}' -f $uri) 121 | 122 | Write-Verbose -Message 'Sending sticker...' 123 | $invokeRestMethodSplat = @{ 124 | Uri = $uri 125 | Body = (ConvertTo-Json -Compress -InputObject $payload) 126 | ErrorAction = 'Stop' 127 | ContentType = 'application/json' 128 | Method = 'Post' 129 | } 130 | try { 131 | Write-Verbose -Message 'Sending message...' 132 | $results = Invoke-RestMethod @invokeRestMethodSplat 133 | } #try_messageSend 134 | catch { 135 | Write-Warning -Message 'An error was encountered sending the Telegram message:' 136 | Write-Error $_ 137 | if ($_.ErrorDetails) { 138 | $results = $_.ErrorDetails | ConvertFrom-Json -ErrorAction SilentlyContinue 139 | } 140 | else { 141 | throw $_ 142 | } 143 | } #catch_messageSend 144 | 145 | return $results 146 | } #function_Send-TelegramURLSticker 147 | -------------------------------------------------------------------------------- /src/PoshGram/Public/Test-BotToken.ps1: -------------------------------------------------------------------------------- 1 | <# 2 | .SYNOPSIS 3 | Validates Bot auth Token 4 | .DESCRIPTION 5 | A simple method for testing your bot's auth token. Requires no parameters. Returns basic information about the bot in form of a User object. 6 | .EXAMPLE 7 | $botToken = 'nnnnnnnnn:xxxxxxx-xxxxxxxxxxxxxxxxxxxxxxxxxxx' 8 | Test-BotToken -BotToken $botToken 9 | 10 | Validates the specified Bot auth token via Telegram API 11 | .EXAMPLE 12 | $botToken = 'nnnnnnnnn:xxxxxxx-xxxxxxxxxxxxxxxxxxxxxxxxxxx' 13 | $testBotTokenSplat = @{ 14 | BotToken = $botToken 15 | Verbose = $true 16 | } 17 | Test-BotToken @testBotTokenSplat 18 | 19 | Validates the specified Bot auth token via Telegram API 20 | .PARAMETER BotToken 21 | Use this token to access the HTTP API 22 | .OUTPUTS 23 | System.Management.Automation.PSCustomObject 24 | .NOTES 25 | Author: Jake Morrison - @jakemorrison - https://www.techthoughts.info/ 26 | 27 | Questions on how to set up a bot, get a token, or get your channel ID? 28 | Answers on the PoshGram documentation: https://poshgram.readthedocs.io/en/latest/PoshGram-FAQ/ 29 | .COMPONENT 30 | PoshGram 31 | .FUNCTIONALITY 32 | A simple method for testing your bot's auth token. Requires no parameters. Returns basic information about the bot in form of a User object. 33 | .LINK 34 | https://poshgram.readthedocs.io/en/latest/Test-BotToken 35 | .LINK 36 | https://core.telegram.org/bots/api#getme 37 | .LINK 38 | https://core.telegram.org/bots/api 39 | #> 40 | function Test-BotToken { 41 | [CmdletBinding()] 42 | param ( 43 | [Parameter(Mandatory = $true, 44 | HelpMessage = '#########:xxxxxxx-xxxxxxxxxxxxxxxxxxxxxxxxxxx')] 45 | [ValidateNotNull()] 46 | [ValidateNotNullOrEmpty()] 47 | [string]$BotToken 48 | ) 49 | 50 | Write-Verbose -Message ('Starting: {0}' -f $MyInvocation.Mycommand) 51 | 52 | $uri = 'https://api.telegram.org/bot{0}/getMe' -f $BotToken 53 | Write-Debug -Message ('Base URI: {0}' -f $uri) 54 | 55 | Write-Verbose -Message 'Testing Bot Token...' 56 | $invokeRestMethodSplat = @{ 57 | Uri = $uri 58 | ErrorAction = 'Stop' 59 | Method = 'Get' 60 | } 61 | try { 62 | $results = Invoke-RestMethod @invokeRestMethodSplat 63 | } #try_messageSend 64 | catch { 65 | Write-Warning -Message 'An error was encountered testing the BOT token:' 66 | if ($_.ErrorDetails) { 67 | $results = $_.ErrorDetails | ConvertFrom-Json -ErrorAction SilentlyContinue 68 | } 69 | else { 70 | throw $_ 71 | } 72 | } #catch_messageSend 73 | 74 | return $results 75 | } #function_Test-BotToken 76 | -------------------------------------------------------------------------------- /src/Tests/Unit/ExportedFunctions.Tests.ps1: -------------------------------------------------------------------------------- 1 | #------------------------------------------------------------------------- 2 | Set-Location -Path $PSScriptRoot 3 | #------------------------------------------------------------------------- 4 | $ModuleName = 'PoshGram' 5 | $PathToManifest = [System.IO.Path]::Combine('..', '..', $ModuleName, "$ModuleName.psd1") 6 | #------------------------------------------------------------------------- 7 | if (Get-Module -Name $ModuleName -ErrorAction 'SilentlyContinue') { 8 | #if the module is already in memory, remove it 9 | Remove-Module -Name $ModuleName -Force 10 | } 11 | Import-Module $PathToManifest -Force 12 | #------------------------------------------------------------------------- 13 | BeforeAll { 14 | Set-Location -Path $PSScriptRoot 15 | $ModuleName = 'PoshGram' 16 | $PathToManifest = [System.IO.Path]::Combine('..', '..', $ModuleName, "$ModuleName.psd1") 17 | $manifestContent = Test-ModuleManifest -Path $PathToManifest 18 | $moduleExported = Get-Command -Module $ModuleName | Select-Object -ExpandProperty Name 19 | $manifestExported = ($manifestContent.ExportedFunctions).Keys 20 | } 21 | Describe -Name $ModuleName -Fixture { 22 | 23 | Context -Name 'Exported Commands' -Fixture { 24 | 25 | Context -Name 'Number of commands' -Fixture { 26 | It -Name 'Exports the same number of public functions as what is listed in the Module Manifest' -Test { 27 | $manifestExported.Count | Should -BeExactly $moduleExported.Count 28 | } 29 | } 30 | 31 | Context -Name 'Explicitly exported commands' -Fixture { 32 | foreach ($command in $moduleExported) { 33 | It -Name "Includes the $command in the Module Manifest ExportedFunctions" -Test { 34 | $manifestExported -contains $command | Should -BeTrue 35 | } 36 | } 37 | } 38 | } 39 | 40 | Context -Name 'Command Help' -Fixture { 41 | foreach ($command in $moduleExported) { 42 | Context -Name $command -Fixture { 43 | $help = Get-Help -Name $command -Full 44 | 45 | It -Name 'Includes a Synopsis' -Test { 46 | $help.SYNOPSIS | Should -Not -BeNullOrEmpty 47 | } 48 | 49 | It -Name 'Includes a Description' -Test { 50 | $help.description.Text | Should -Not -BeNullOrEmpty 51 | } 52 | 53 | It -Name 'Includes an Example' -Test { 54 | $help.examples.example | Should -Not -BeNullOrEmpty 55 | } 56 | } 57 | } 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /src/Tests/Unit/PoshGram-Module.Tests.ps1: -------------------------------------------------------------------------------- 1 | BeforeAll { 2 | #------------------------------------------------------------------------- 3 | Set-Location -Path $PSScriptRoot 4 | #------------------------------------------------------------------------- 5 | $ModuleName = 'PoshGram' 6 | $PathToManifest = [System.IO.Path]::Combine('..', '..', $ModuleName, "$ModuleName.psd1") 7 | $PathToModule = [System.IO.Path]::Combine('..', '..', $ModuleName, "$ModuleName.psm1") 8 | #------------------------------------------------------------------------- 9 | } 10 | Describe 'Module Tests' -Tag Unit { 11 | Context "Module Tests" { 12 | $script:manifestEval = $null 13 | It 'Passes Test-ModuleManifest' { 14 | { $script:manifestEval = Test-ModuleManifest -Path $PathToManifest } | Should -Not -Throw 15 | $? | Should -BeTrue 16 | } #manifestTest 17 | It 'root module PoshGram.psm1 should exist' { 18 | $PathToModule | Should -Exist 19 | $? | Should -BeTrue 20 | } #psm1Exists 21 | It 'manifest should contain PoshGram.psm1' { 22 | $PathToManifest | 23 | Should -FileContentMatchExactly "PoshGram.psm1" 24 | } #validPSM1 25 | It 'should have a matching module name in the manifest' { 26 | $script:manifestEval.Name | Should -BeExactly $ModuleName 27 | } #name 28 | It 'should have a valid description in the manifest' { 29 | $script:manifestEval.Description | Should -Not -BeNullOrEmpty 30 | } #description 31 | It 'should have a valid author in the manifest' { 32 | $script:manifestEval.Author | Should -Not -BeNullOrEmpty 33 | } #author 34 | It 'should have a valid version in the manifest' { 35 | $script:manifestEval.Version -as [Version] | Should -Not -BeNullOrEmpty 36 | } #version 37 | It 'should have a valid guid in the manifest' { 38 | { [guid]::Parse($script:manifestEval.Guid) } | Should -Not -Throw 39 | } #guid 40 | It 'should not have any spaces in the tags' { 41 | foreach ($tag in $script:manifestEval.Tags) { 42 | $tag | Should -Not -Match '\s' 43 | } 44 | } #tagSpaces 45 | It 'should have a valid project Uri' { 46 | $script:manifestEval.ProjectUri | Should -Not -BeNullOrEmpty 47 | } #uri 48 | } #context_ModuleTests 49 | } #describe_ModuleTests 50 | -------------------------------------------------------------------------------- /src/Tests/Unit/Private/Add-EmojiDetail.Tests.ps1: -------------------------------------------------------------------------------- 1 | #------------------------------------------------------------------------- 2 | Set-Location -Path $PSScriptRoot 3 | #------------------------------------------------------------------------- 4 | $ModuleName = 'PoshGram' 5 | $PathToManifest = [System.IO.Path]::Combine('..', '..', '..', $ModuleName, "$ModuleName.psd1") 6 | #------------------------------------------------------------------------- 7 | if (Get-Module -Name $ModuleName -ErrorAction 'SilentlyContinue') { 8 | #if the module is already in memory, remove it 9 | Remove-Module -Name $ModuleName -Force 10 | } 11 | Import-Module $PathToManifest -Force 12 | #------------------------------------------------------------------------- 13 | 14 | InModuleScope PoshGram { 15 | Describe 'Add-EmojiDetail' -Tag Unit { 16 | BeforeAll { 17 | $WarningPreference = 'SilentlyContinue' 18 | $ErrorActionPreference = 'SilentlyContinue' 19 | function Get-Emoji { 20 | } 21 | } #beforeAll 22 | BeforeEach { 23 | $token = '#########:xxxxxxx-xxxxxxxxxxxxxxxxxxxxxxxxxxx' 24 | 25 | $stickerObject = [PSCustomObject]@{ 26 | ok = 'True' 27 | result = [PSCustomObject]@{ 28 | Name = 'STPicard' 29 | title = 'Picard' 30 | is_animated = 'False' 31 | contains_masks = 'False' 32 | stickers = [PSCustomObject]@{ 33 | width = '512' 34 | height = '512' 35 | emoji = '🙂' 36 | set_name = 'STPicard' 37 | is_animated = 'False' 38 | thumb = '@{file_id=AAQCAAMMAAPdcBMXl0FGgL2-fdo_kOMNAAQBAAdtAAPeLQACFgQ; file_size=3810; width=128; height=128}' 39 | file_id = 'CAADAgADDAAD3XATF5dBRoC9vn3aFgQ' 40 | file_size = '18356' 41 | Bytes = '{61, 216, 66, 222}' 42 | Code = 'U+1F642' 43 | Shortcode = ':slightly_smiling_face:' 44 | } 45 | } 46 | } 47 | 48 | Mock Get-Emoji -MockWith { 49 | [PSCustomObject]@{ 50 | Group = 'Smileys & Emotion' 51 | Subgroup = 'face-smiling' 52 | HexCodePoint = '1F642' 53 | Name = '🙂' 54 | Description = 'slightly smiling face' 55 | ShortCode = ':slightly_smiling_face:' 56 | HexCodePointArray = @('1F642') 57 | UnicodeStandard = @('U+1F642') 58 | pwshEscapedFormat = '`u{1F642}' 59 | Decimal = @(128578) 60 | } 61 | } #endMock 62 | 63 | } #before_each 64 | 65 | Context 'Error' { 66 | It 'should not throw if an error is encountered' { 67 | Mock Get-Emoji -MockWith { 68 | throw 'Fake Error' 69 | } #endMock 70 | $getTelegramStickerPackInfoSplat = @{ 71 | BotToken = $token 72 | StickerSetName = 'STPicard' 73 | } 74 | { Add-EmojiDetail -StickerObject $stickerObject.result.stickers } | Should -Not -Throw 75 | } #it 76 | 77 | } #context_Error 78 | 79 | Context 'Success' { 80 | 81 | It 'should still return the original object if no emoji data is found' { 82 | Mock -CommandName Get-Emoji -MockWith { 83 | $null 84 | } #endMock 85 | 86 | $eval = Add-EmojiDetail -StickerObject $stickerObject.result.stickers 87 | $eval | Should -BeExactly $stickerObject.result.stickers 88 | } #it 89 | 90 | It 'should return a custom PSCustomObject if successful' { 91 | $eval = Add-EmojiDetail -StickerObject $stickerObject.result.stickers 92 | $eval.width | Should -BeExactly '512' 93 | $eval.height | Should -BeExactly '512' 94 | $eval.emoji | Should -BeExactly '🙂' 95 | $eval.set_name | Should -BeExactly 'STPicard' 96 | $eval.is_animated | Should -BeExactly 'False' 97 | $eval.thumb | Should -BeExactly '@{file_id=AAQCAAMMAAPdcBMXl0FGgL2-fdo_kOMNAAQBAAdtAAPeLQACFgQ; file_size=3810; width=128; height=128}' 98 | $eval.file_id | Should -BeExactly 'CAADAgADDAAD3XATF5dBRoC9vn3aFgQ' 99 | $eval.file_size | Should -BeExactly '18356' 100 | $eval.Group | Should -BeExactly 'Smileys & Emotion' 101 | $eval.Subgroup | Should -BeExactly 'face-smiling' 102 | $eval.Code | Should -Contain 'U+1F642' 103 | $eval.pwshEscapedFormat | Should -BeExactly '`u{1F642}' 104 | $eval.Shortcode | Should -BeExactly ':slightly_smiling_face:' 105 | } #it 106 | } #context_Success 107 | 108 | } #describe_Add-EmojiDetail 109 | } #inModule 110 | -------------------------------------------------------------------------------- /src/Tests/Unit/Private/Confirm-URL.Tests.ps1: -------------------------------------------------------------------------------- 1 | #------------------------------------------------------------------------- 2 | Set-Location -Path $PSScriptRoot 3 | #------------------------------------------------------------------------- 4 | $ModuleName = 'PoshGram' 5 | $PathToManifest = [System.IO.Path]::Combine('..', '..', '..', $ModuleName, "$ModuleName.psd1") 6 | #------------------------------------------------------------------------- 7 | if (Get-Module -Name $ModuleName -ErrorAction 'SilentlyContinue') { 8 | #if the module is already in memory, remove it 9 | Remove-Module -Name $ModuleName -Force 10 | } 11 | Import-Module $PathToManifest -Force 12 | 13 | InModuleScope PoshGram { 14 | #------------------------------------------------------------------------- 15 | $WarningPreference = 'SilentlyContinue' 16 | function Write-Error { 17 | } 18 | #------------------------------------------------------------------------- 19 | Describe 'Confirm-URL' -Tag Unit { 20 | BeforeAll { 21 | $WarningPreference = 'SilentlyContinue' 22 | $ErrorActionPreference = 'SilentlyContinue' 23 | } #beforeAll 24 | 25 | It 'should return false if the website can not be reached' { 26 | Mock Invoke-WebRequest -MockWith { 27 | [System.Exception]$exception = 'No such host is known' 28 | [System.String]$errorId = 'InvalidOperation$' 29 | [Management.Automation.ErrorCategory]$errorCategory = [Management.Automation.ErrorCategory]::InvalidOperation 30 | [System.Object]$target = 'Whatevs' 31 | $errorRecord = New-Object Management.Automation.ErrorRecord ($exception, $errorID, $errorCategory, $target) 32 | [System.Management.Automation.ErrorDetails]$errorDetails = '{"message":"No such host is known"}' 33 | $errorRecord.ErrorDetails = $errorDetails 34 | throw $errorRecord 35 | } #endMock 36 | Confirm-URL -Uri 'https://bssite.is/2nlyzm4' | Should -Be $false 37 | } #it 38 | 39 | It 'should return true when a website can be reached' { 40 | Mock Invoke-WebRequest -MockWith { 41 | [PSCustomObject]@{ 42 | StatusCode = '200' 43 | StatusDescription = 'OK' 44 | Content = '{137, 80, 78, 71...}' 45 | RawContent = 'HTTP/1.1 200 OK' 46 | Headers = "{[Content-Security-Policy, default-src 'none'; style-src 'unsafe-inline'; sandbox], [Strict-Transport-Security, max-age=31536000], [X-Content-Type-Options, nosniff]" 47 | RawContentLength = '119136' 48 | } 49 | } #endMock 50 | Confirm-URL -Uri 'https://gph.is/2nlyzm4' | Should -Be $true 51 | } #it 52 | 53 | } #describe 54 | } #inModule 55 | -------------------------------------------------------------------------------- /src/Tests/Unit/Private/Resolve-ShortLink.Tests.ps1: -------------------------------------------------------------------------------- 1 | #------------------------------------------------------------------------- 2 | Set-Location -Path $PSScriptRoot 3 | #------------------------------------------------------------------------- 4 | $ModuleName = 'PoshGram' 5 | $PathToManifest = [System.IO.Path]::Combine('..', '..', '..', $ModuleName, "$ModuleName.psd1") 6 | #------------------------------------------------------------------------- 7 | if (Get-Module -Name $ModuleName -ErrorAction 'SilentlyContinue') { 8 | #if the module is already in memory, remove it 9 | Remove-Module -Name $ModuleName -Force 10 | } 11 | Import-Module $PathToManifest -Force 12 | 13 | InModuleScope PoshGram { 14 | Describe 'Resolve-ShortLink' -Tag Unit { 15 | BeforeAll { 16 | $WarningPreference = 'SilentlyContinue' 17 | $ErrorActionPreference = 'SilentlyContinue' 18 | } #beforeAll 19 | Context 'Error' { 20 | 21 | It 'should return the absolute uri if one is detected' { 22 | Mock Invoke-WebRequest -MockWith { 23 | $errorDetails = '{"code": 21212, "message": "The ''From'' number is not a valid phone number, shortcode, or alphanumeric sender ID.", "more_info": "https://www.twilio.com/docs/errors/21212", "status": 400}' 24 | # [System.Net.Http.Headers.HttpHeaders] = @{ 25 | # Location = @{ 26 | # AbsoluteUri = 'http://www.google.com' 27 | # } 28 | # } 29 | [System.Net.Http.Headers.HttpHeaders]::new() | Add-Member -MemberType NoteProperty -Name 'Location' -Value @{ 30 | AbsoluteUri = 'http://www.google.com' 31 | } 32 | $statusCode = 301 33 | $response = New-Object System.Net.Http.HttpResponseMessage $statusCode 34 | $response.Headers = @{ 35 | Location = @{ 36 | AbsoluteUri = 'http://www.google.com' 37 | } 38 | } 39 | $exception = New-Object Microsoft.PowerShell.Commands.HttpResponseException "$statusCode ($($response.ReasonPhrase))", $response 40 | # https://groups.google.com/g/pester/c/ZgNpVc36Z0k?pli=1 41 | #___________________ 42 | [System.Exception]$exception = "The remote server returned an error: (400) Bad Request." 43 | [System.String]$errorId = 'BadRequest' 44 | [Management.Automation.ErrorCategory]$errorCategory = [Management.Automation.ErrorCategory]::InvalidOperation 45 | [System.Object]$target = 'Whatevs' 46 | $errorRecord = New-Object Management.Automation.ErrorRecord ($exception, $errorID, $errorCategory, $target) 47 | [System.Management.Automation.ErrorDetails]$errorDetails = '{"message":"Username does not exist: [user]"}' 48 | $errorRecord.ErrorDetails = $errorDetails 49 | throw $errorRecord 50 | } #endMock 51 | } #it 52 | 53 | } #context_error 54 | 55 | Context 'Success' { 56 | 57 | It 'should return null if no redirect detected' { 58 | Resolve-ShortLink -Uri 'https://www.google.com' | Should -BeNullOrEmpty 59 | } #it 60 | 61 | } #context_success 62 | #I haven't figured out at this time how to properly mock Invoke-WebRequest errors that indicate a re-direction condition. 63 | #as such, there is no test coverage for this function at this time 64 | <# 65 | it 'should return the redirected URL if a Moved header is found' { 66 | 67 | Mock Invoke-WebRequest -MockWith { 68 | 69 | [Microsoft.PowerShell.Commands.HttpResponseException]$Exception = @{ 70 | 71 | } 72 | } 73 | 74 | Mock Invoke-WebRequest -MockWith { 75 | [System.Exception]$exception = 'Operation is not valid due to the current state of the object.' 76 | [System.String]$errorId = 'WebCmdletWebResponseException$' 77 | [Management.Automation.ErrorCategory]$errorCategory = [Management.Automation.ErrorCategory]::InvalidOperation 78 | [System.Object]$target = 'Whatevs' 79 | $errorRecord = New-Object Management.Automation.ErrorRecord ($exception, $errorID,$errorCategory, $target) 80 | [System.Management.Automation.ErrorDetails]$errorDetails = '{"message":"The maximum redirection count has been exceeded. To increase the number of redirections allowed 81 | , supply a higher value to the -MaximumRedirection parameter."}' 82 | $errorRecord.ErrorDetails = $errorDetails 83 | throw $errorRecord 84 | } #endMock 85 | Resolve-ShortLink -Uri 'https://gph.is/2nlyzm4' | Should 86 | 87 | } #it 88 | $hi = [System.Net.Http.HttpResponseMessage]::new() 89 | $hi.Headers = [System.Net.Http.Headers.HttpResponseHeaders]::Equals() 90 | [System.Net.Http.HttpResponseMessage] = @( 91 | Headers = [System.Net.Http.Headers.HttpResponseHeaders] = @( 92 | Location = @ { 93 | AbsoluteUri = 'https://giphy.com/gifs/cbs-star-trek-3o7WIxTr05mKzBTFUk' 94 | } 95 | ) 96 | ) 97 | 98 | Mock Invoke-WebRequest -MockWith { 99 | [PSCustomObject]@{ 100 | StatusCode = "200" 101 | StatusDescription = "OK" 102 | Content = "{137, 80, 78, 71...}" 103 | RawContent = "HTTP/1.1 200 OK" 104 | Headers = "{[Content-Security-Policy, default-src 'none'; style-src 'unsafe-inline'; sandbox], [Strict-Transport-Security, max-age=31536000], [X-Content-Type-Options, nosniff]" 105 | RawContentLength = "119136" 106 | } 107 | } #endMock 108 | } #it 109 | #> 110 | } #describe 111 | } #inModule 112 | -------------------------------------------------------------------------------- /src/Tests/Unit/Private/Test-Explanation.Tests.ps1: -------------------------------------------------------------------------------- 1 | #------------------------------------------------------------------------- 2 | Set-Location -Path $PSScriptRoot 3 | #------------------------------------------------------------------------- 4 | $ModuleName = 'PoshGram' 5 | $PathToManifest = [System.IO.Path]::Combine('..', '..', '..', $ModuleName, "$ModuleName.psd1") 6 | #------------------------------------------------------------------------- 7 | if (Get-Module -Name $ModuleName -ErrorAction 'SilentlyContinue') { 8 | #if the module is already in memory, remove it 9 | Remove-Module -Name $ModuleName -Force 10 | } 11 | Import-Module $PathToManifest -Force 12 | 13 | InModuleScope PoshGram { 14 | Describe 'Test-Explanation' -Tag Unit { 15 | BeforeAll { 16 | $WarningPreference = 'SilentlyContinue' 17 | $ErrorActionPreference = 'SilentlyContinue' 18 | } #beforeAll 19 | 20 | It 'should return false if the explanation exceeds 200 characters' { 21 | $explanation = 'Space: the final frontier. These are the voyages of the starship Enterprise. Its five-year mission: to explore strange new worlds. To seek out new life and new civilizations. To boldly go where no man has gone before!' 22 | Test-Explanation -Explanation $explanation | Should -Be $false 23 | } #it 24 | 25 | It 'should return false if the explanation has more than 2 line feeds' { 26 | $explanation = @' 27 | The Original Series 28 | The Animated Series 29 | The Next Generation 30 | Deep Space Nine 31 | Voyager 32 | Enterprise 33 | Discovery 34 | Picard 35 | Lower Decks 36 | Prodigy 37 | '@ 38 | Test-Explanation -Explanation $explanation | Should -Be $false 39 | } #it 40 | 41 | It 'should return true if the explanation meets criteria' { 42 | $explanation = 'The Invincible-class is the single largest multi-mission combat-equipped starship ever constructed by Starfleet.' 43 | Test-Explanation -Explanation $explanation | Should -Be $true 44 | } #it 45 | 46 | } #describe 47 | } #inModule 48 | -------------------------------------------------------------------------------- /src/Tests/Unit/Private/Test-FileExtension.Tests.ps1: -------------------------------------------------------------------------------- 1 | #------------------------------------------------------------------------- 2 | Set-Location -Path $PSScriptRoot 3 | #------------------------------------------------------------------------- 4 | $ModuleName = 'PoshGram' 5 | $PathToManifest = [System.IO.Path]::Combine('..', '..', '..', $ModuleName, "$ModuleName.psd1") 6 | #------------------------------------------------------------------------- 7 | if (Get-Module -Name $ModuleName -ErrorAction 'SilentlyContinue') { 8 | #if the module is already in memory, remove it 9 | Remove-Module -Name $ModuleName -Force 10 | } 11 | Import-Module $PathToManifest -Force 12 | 13 | InModuleScope PoshGram { 14 | Describe 'Test-FileExtension' -Tag Unit { 15 | BeforeAll { 16 | $WarningPreference = 'SilentlyContinue' 17 | $ErrorActionPreference = 'SilentlyContinue' 18 | } #beforeAll 19 | BeforeEach { 20 | $supportedPhotoExtensions = @( 21 | 'JPG', 22 | 'JPEG', 23 | 'PNG', 24 | 'GIF', 25 | 'BMP', 26 | 'WEBP', 27 | 'SVG', 28 | 'TIFF' 29 | ) 30 | $supportedVideoExtensions = @( 31 | 'mp4' 32 | ) 33 | $supportedAudioExtensions = @( 34 | 'mp3', 35 | 'm4a' 36 | ) 37 | $supportedAnimationExtensions = @( 38 | 'GIF' 39 | ) 40 | $supportedStickerExtensions = @( 41 | 'WEBP', 42 | 'TGS', 43 | 'WEBM' 44 | ) 45 | } #before_each 46 | 47 | It 'should return false when a non-supported extension is provided' { 48 | Test-FileExtension -FilePath c:\fakepath\fakefile.txt ` 49 | -Type Photo | Should -Be $false 50 | Test-FileExtension -FilePath c:\fakepath\fakefile.txt ` 51 | -Type Video | Should -Be $false 52 | Test-FileExtension -FilePath c:\fakepath\fakefile.txt ` 53 | -Type Audio | Should -Be $false 54 | Test-FileExtension -FilePath c:\fakepath\fakefile.txt ` 55 | -Type Animation | Should -Be $false 56 | Test-FileExtension -FilePath c:\fakepath\fakefile.txt ` 57 | -Type Sticker | Should -Be $false 58 | } #it 59 | 60 | Context 'Photo' { 61 | foreach ($extension in $supportedPhotoExtensions) { 62 | It "should return true when $extension extension is provided" { 63 | Test-FileExtension -FilePath c:\fakepath\fakefile.$extension ` 64 | -Type Photo | Should -Be $true 65 | } #it 66 | } #foreach 67 | } #context_Photo 68 | 69 | Context 'Video' { 70 | foreach ($extension in $supportedVideoExtensions) { 71 | It "should return true when $extension extension is provided" { 72 | Test-FileExtension -FilePath c:\fakepath\fakefile.$extension ` 73 | -Type Video | Should -Be $true 74 | } #it 75 | } #foreach 76 | } #context_Video 77 | 78 | Context 'Audio' { 79 | foreach ($extension in $supportedAudioExtensions) { 80 | It "should return true when $extension extension is provided" { 81 | Test-FileExtension -FilePath c:\fakepath\fakefile.$extension ` 82 | -Type Audio | Should -Be $true 83 | } #it 84 | } #foreach 85 | } #context_Audio 86 | 87 | Context 'Animation' { 88 | foreach ($extension in $supportedAnimationExtensions) { 89 | It "should return true when $extension extension is provided" { 90 | Test-FileExtension -FilePath c:\fakepath\fakefile.$extension ` 91 | -Type Animation | Should -Be $true 92 | } #it 93 | } #foreach 94 | } #context_Animation 95 | 96 | Context 'Sticker' { 97 | foreach ($extension in $supportedStickerExtensions) { 98 | It "should return true when $extension extension is provided" { 99 | Test-FileExtension -FilePath c:\fakepath\fakefile.$extension ` 100 | -Type Sticker | Should -Be $true 101 | } #it 102 | } #foreach 103 | } #context_Animation 104 | 105 | } #describe 106 | } #inModule 107 | -------------------------------------------------------------------------------- /src/Tests/Unit/Private/Test-FileSize.Tests.ps1: -------------------------------------------------------------------------------- 1 | #------------------------------------------------------------------------- 2 | Set-Location -Path $PSScriptRoot 3 | #------------------------------------------------------------------------- 4 | $ModuleName = 'PoshGram' 5 | $PathToManifest = [System.IO.Path]::Combine('..', '..', '..', $ModuleName, "$ModuleName.psd1") 6 | #------------------------------------------------------------------------- 7 | if (Get-Module -Name $ModuleName -ErrorAction 'SilentlyContinue') { 8 | #if the module is already in memory, remove it 9 | Remove-Module -Name $ModuleName -Force 10 | } 11 | Import-Module $PathToManifest -Force 12 | 13 | InModuleScope PoshGram { 14 | Describe 'Test-FileSize' -Tag Unit { 15 | BeforeAll { 16 | $WarningPreference = 'SilentlyContinue' 17 | $ErrorActionPreference = 'SilentlyContinue' 18 | } #beforeAll 19 | It 'Should return true when the file is at or below 50MB' { 20 | Mock Get-ChildItem -MockWith { 21 | [PSCustomObject]@{ 22 | Mode = '-a----' 23 | LastWriteTime = '06/30/18 09:52' 24 | Length = '119136' 25 | Name = 'techthoughts.png' 26 | } 27 | } #endMock 28 | Test-FileSize -Path 'C:\videos\video.mp4' | Should -Be $true 29 | } #it 30 | It 'should return false when the file is over 50MB' { 31 | Mock Get-ChildItem -MockWith { 32 | [PSCustomObject]@{ 33 | Mode = '-a----' 34 | LastWriteTime = '06/30/18 09:52' 35 | Length = '1593681272' 36 | Name = 'techthoughts.png' 37 | } 38 | } #endMock 39 | Test-FileSize -Path 'C:\videos\video.mp4' | Should -Be $false 40 | } #it 41 | It 'should return false when an error is encountered' { 42 | Mock Get-ChildItem -MockWith { 43 | throw 'Fake Error' 44 | } #endMock 45 | Test-FileSize -Path 'C:\videos\video.mp4' | Should -Be $false 46 | } #it 47 | } #describe 48 | } #inModule 49 | -------------------------------------------------------------------------------- /src/Tests/Unit/Private/Test-MediaGroupRequirements.Tests.ps1: -------------------------------------------------------------------------------- 1 | #------------------------------------------------------------------------- 2 | Set-Location -Path $PSScriptRoot 3 | #------------------------------------------------------------------------- 4 | $ModuleName = 'PoshGram' 5 | $PathToManifest = [System.IO.Path]::Combine('..', '..', '..', $ModuleName, "$ModuleName.psd1") 6 | #------------------------------------------------------------------------- 7 | if (Get-Module -Name $ModuleName -ErrorAction 'SilentlyContinue') { 8 | #if the module is already in memory, remove it 9 | Remove-Module -Name $ModuleName -Force 10 | } 11 | Import-Module $PathToManifest -Force 12 | 13 | InModuleScope PoshGram { 14 | Describe 'Test-MediaGroupRequirements' -Tag Unit { 15 | BeforeAll { 16 | $WarningPreference = 'SilentlyContinue' 17 | $ErrorActionPreference = 'SilentlyContinue' 18 | } #beforeAll 19 | BeforeEach { 20 | Mock Test-Path { $true } 21 | Mock Test-FileExtension { $true } 22 | Mock Test-FileSize { $true } 23 | $justRight = @( 24 | 'photo1.jpg', 25 | 'photo2.jpg' 26 | ) 27 | } #before_each 28 | 29 | It 'should return false if the files provided are fewer than 2' { 30 | $tooFew = @( 31 | 'photo1.jpg' 32 | ) 33 | $testMediaGroupRequirementsSplat = @{ 34 | MediaType = 'Photo' 35 | FilePaths = $tooFew 36 | } 37 | Test-MediaGroupRequirements @testMediaGroupRequirementsSplat | Should -Be $false 38 | } #it 39 | 40 | It 'should return false if the files provided are great than 10' { 41 | $tooMany = @( 42 | 'photo1.jpg', 43 | 'photo2.jpg', 44 | 'photo3.jpg', 45 | 'photo4.jpg', 46 | 'photo5.jpg', 47 | 'photo6.jpg', 48 | 'photo7.jpg', 49 | 'photo8.jpg', 50 | 'photo9.jpg', 51 | 'photo10.jpg', 52 | 'photo11.jpg' 53 | ) 54 | $testMediaGroupRequirementsSplat = @{ 55 | MediaType = 'Photo' 56 | FilePaths = $tooMany 57 | } 58 | Test-MediaGroupRequirements @testMediaGroupRequirementsSplat | Should -Be $false 59 | } #it 60 | 61 | It 'should return false if the media can not be found' { 62 | Mock Test-Path { $false } 63 | $testMediaGroupRequirementsSplat = @{ 64 | MediaType = 'Photo' 65 | FilePaths = $justRight 66 | } 67 | Test-MediaGroupRequirements @testMediaGroupRequirementsSplat | Should -Be $false 68 | } #it 69 | 70 | It 'should return false if the media extension is not supported' { 71 | Mock Test-FileExtension { $false } 72 | $testMediaGroupRequirementsSplat = @{ 73 | MediaType = 'Photo' 74 | FilePaths = $justRight 75 | } 76 | Test-MediaGroupRequirements @testMediaGroupRequirementsSplat | Should -Be $false 77 | } #it 78 | 79 | It 'should return false if the media is too large' { 80 | Mock Test-FileSize { $false } 81 | $testMediaGroupRequirementsSplat = @{ 82 | MediaType = 'Video' 83 | FilePaths = $justRight 84 | } 85 | Test-MediaGroupRequirements @testMediaGroupRequirementsSplat | Should -Be $false 86 | } #it 87 | 88 | It 'should return true if all conditions are met' { 89 | $testMediaGroupRequirementsSplat = @{ 90 | MediaType = 'Video' 91 | FilePaths = $justRight 92 | } 93 | Test-MediaGroupRequirements @testMediaGroupRequirementsSplat | Should -Be $true 94 | } #it 95 | 96 | } #describe 97 | } #inModule 98 | -------------------------------------------------------------------------------- /src/Tests/Unit/Private/Test-PollOptions.Tests.ps1: -------------------------------------------------------------------------------- 1 | #------------------------------------------------------------------------- 2 | Set-Location -Path $PSScriptRoot 3 | #------------------------------------------------------------------------- 4 | $ModuleName = 'PoshGram' 5 | $PathToManifest = [System.IO.Path]::Combine('..', '..', '..', $ModuleName, "$ModuleName.psd1") 6 | #------------------------------------------------------------------------- 7 | if (Get-Module -Name $ModuleName -ErrorAction 'SilentlyContinue') { 8 | #if the module is already in memory, remove it 9 | Remove-Module -Name $ModuleName -Force 10 | } 11 | Import-Module $PathToManifest -Force 12 | 13 | InModuleScope PoshGram { 14 | Describe 'Test-PollOptions' -Tag Unit { 15 | BeforeAll { 16 | $WarningPreference = 'SilentlyContinue' 17 | $ErrorActionPreference = 'SilentlyContinue' 18 | } #beforeAll 19 | 20 | It 'should return false if the number of options is below 2' { 21 | $opt = @( 22 | 'One' 23 | ) 24 | Test-PollOptions -PollOptions $opt | Should -Be $false 25 | } #it 26 | 27 | It 'should return false if the number of options is above 10' { 28 | $opt = @( 29 | 'One', 30 | 'Two', 31 | 'Three', 32 | 'Four', 33 | 'Five', 34 | 'Six', 35 | 'Seven', 36 | 'Eight', 37 | 'Nine', 38 | 'Ten', 39 | 'Eleven' 40 | ) 41 | Test-PollOptions -PollOptions $opt | Should -Be $false 42 | } #it 43 | 44 | It 'should return false if an option has a character count above 300' { 45 | $opt = @( 46 | 'Three', 47 | 'Four', 48 | 'uhvfulonqhitqljlpyiziijocidwiljbjyezzkzmvcahymsppqpqrhxpcdqbaikjbkevsohjnjtdrmrvwoconbqeaemouzzpypeeguhvfulonqhitqljlpyiziijocidwiljbjyezzkzmvcahymsppqpqrhxpcdqbaikjbkevsohjnjtdrmrvwoconbqeaemouzzpypeeguhvfulonqhitqljlpyiziijocidwiljbjyezzkzmvcahymsppqpqrhxpcdqbaikjbkevsohjnjtdrmrvwoconbqeaemouzzpypeeg' 49 | ) 50 | Test-PollOptions -PollOptions $opt | Should -Be $false 51 | } #it 52 | 53 | It 'should return true if a valid set of options is provided' { 54 | $opt = @( 55 | 'Star Trek: The Original Series', 56 | 'Star Trek: The Animated Series', 57 | 'Star Trek: The Next Generation', 58 | 'Star Trek: Deep Space Nine', 59 | 'Star Trek: Voyager', 60 | 'Star Trek: Enterprise', 61 | 'Star Trek: Discovery', 62 | 'Star Trek: Picard' 63 | ) 64 | Test-PollOptions -PollOptions $opt | Should -Be $true 65 | } #it 66 | 67 | } #describe 68 | } #inModule -------------------------------------------------------------------------------- /src/Tests/Unit/Private/Test-URLFileSize.Tests.ps1: -------------------------------------------------------------------------------- 1 | #------------------------------------------------------------------------- 2 | Set-Location -Path $PSScriptRoot 3 | #------------------------------------------------------------------------- 4 | $ModuleName = 'PoshGram' 5 | $PathToManifest = [System.IO.Path]::Combine('..', '..', '..', $ModuleName, "$ModuleName.psd1") 6 | #------------------------------------------------------------------------- 7 | if (Get-Module -Name $ModuleName -ErrorAction 'SilentlyContinue') { 8 | #if the module is already in memory, remove it 9 | Remove-Module -Name $ModuleName -Force 10 | } 11 | Import-Module $PathToManifest -Force 12 | 13 | InModuleScope PoshGram { 14 | Describe 'Test-URLFileSize' -Tag Unit { 15 | BeforeAll { 16 | $WarningPreference = 'SilentlyContinue' 17 | $ErrorActionPreference = 'SilentlyContinue' 18 | } #beforeAll 19 | BeforeEach { 20 | $fileURL = 'https://github.com/techthoughts2/PoshGram/raw/main/test/SourceFiles/LogExample.zip' 21 | } #before_each 22 | 23 | It 'Should return true when the file is at or below 50MB' { 24 | Mock Invoke-WebRequest -MockWith { 25 | [PSCustomObject]@{ 26 | StatusCode = '200' 27 | StatusDescription = 'OK' 28 | Content = '{137, 80, 78, 71...}' 29 | RawContent = 'HTTP/1.1 200 OK' 30 | Headers = "{[Content-Security-Policy, default-src 'none'; style-src 'unsafe-inline'; sandbox], [Strict-Transport-Security, max-age=31536000], [X-Content-Type-Options, nosniff]" 31 | RawContentLength = '119136' 32 | } 33 | } #endMock 34 | Test-URLFileSize -URL $fileURL | Should -Be $true 35 | } #it 36 | 37 | It 'should return false when the file is over 50MB' { 38 | Mock Invoke-WebRequest -MockWith { 39 | [PSCustomObject]@{ 40 | StatusCode = '200' 41 | StatusDescription = 'OK' 42 | Content = '{137, 80, 78, 71...}' 43 | RawContent = 'HTTP/1.1 200 OK' 44 | Headers = "{[Content-Security-Policy, default-src 'none'; style-src 'unsafe-inline'; sandbox], [Strict-Transport-Security, max-age=31536000], [X-Content-Type-Options, nosniff]" 45 | RawContentLength = '1593681272' 46 | } 47 | } #endMock 48 | Test-URLFileSize -URL $fileURL | Should -Be $false 49 | } #it 50 | 51 | It 'should return false when an error is encountered' { 52 | Mock Invoke-WebRequest -MockWith { 53 | throw 'Fake Error' 54 | } #endMock 55 | Test-URLFileSize -URL $fileURL | Should -Be $false 56 | } #it 57 | 58 | } #describe 59 | } #inModule -------------------------------------------------------------------------------- /src/Tests/Unit/Public/Test-BotToken.Tests.ps1: -------------------------------------------------------------------------------- 1 | #------------------------------------------------------------------------- 2 | Set-Location -Path $PSScriptRoot 3 | #------------------------------------------------------------------------- 4 | $ModuleName = 'PoshGram' 5 | $PathToManifest = [System.IO.Path]::Combine('..', '..', '..', $ModuleName, "$ModuleName.psd1") 6 | #------------------------------------------------------------------------- 7 | if (Get-Module -Name $ModuleName -ErrorAction 'SilentlyContinue') { 8 | #if the module is already in memory, remove it 9 | Remove-Module -Name $ModuleName -Force 10 | } 11 | Import-Module $PathToManifest -Force 12 | #------------------------------------------------------------------------- 13 | 14 | InModuleScope PoshGram { 15 | Describe 'Test-BotToken' -Tag Unit { 16 | BeforeAll { 17 | $WarningPreference = 'SilentlyContinue' 18 | $ErrorActionPreference = 'SilentlyContinue' 19 | } #beforeAll 20 | BeforeEach { 21 | $token = '#########:xxxxxxx-xxxxxxxxxxxxxxxxxxxxxxxxxxx' 22 | } #before_each 23 | Context 'Error' { 24 | It 'should throw if an error is encountered with no specific exception' { 25 | Mock Invoke-RestMethod { 26 | throw 'Fake Error' 27 | } #endMock 28 | $testBotTokenSplat = @{ 29 | BotToken = $token 30 | ErrorAction = 'SilentlyContinue' 31 | } 32 | { Test-BotToken @testBotTokenSplat } | Should -Throw 33 | } #it 34 | 35 | It 'should run the expected commands if an error is encountered' { 36 | Mock -CommandName Invoke-RestMethod { 37 | throw 'Fake Error' 38 | } #endMock 39 | Mock -CommandName Write-Warning { } 40 | $testBotTokenSplat = @{ 41 | BotToken = $token 42 | ErrorAction = 'SilentlyContinue' 43 | } 44 | { Test-BotToken @testBotTokenSplat 45 | Should -Invoke -CommandName Write-Warning -Times 1 -Scope It } 46 | } #it 47 | 48 | It 'should return the exception if the API returns an error' { 49 | Mock -CommandName Invoke-RestMethod { 50 | $errorDetails = '{ "ok":false, "error_code":429, "description":"Too Many Requests: retry after 10", "parameters": { "retry_after":10 } }' 51 | $statusCode = 429 52 | $response = New-Object System.Net.Http.HttpResponseMessage $statusCode 53 | $exception = New-Object Microsoft.PowerShell.Commands.HttpResponseException "$statusCode ($($response.ReasonPhrase))", $response 54 | 55 | $errorCategory = [System.Management.Automation.ErrorCategory]::InvalidOperation 56 | 57 | $errorID = 'WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeWebRequestCommand' 58 | $targetObject = $null 59 | $errorRecord = New-Object Management.Automation.ErrorRecord $exception, $errorID, $errorCategory, $targetObject 60 | $errorRecord.ErrorDetails = $errorDetails 61 | throw $errorRecord 62 | } #endMock 63 | $testBotTokenSplat = @{ 64 | BotToken = $token 65 | ErrorAction = 'SilentlyContinue' 66 | } 67 | $eval = Test-BotToken @testBotTokenSplat 68 | $eval.ok | Should -BeExactly 'False' 69 | $eval.error_code | Should -BeExactly '429' 70 | } #it 71 | } #context_error 72 | Context 'Success' { 73 | It 'should call the API with the expected parameters' { 74 | Mock -CommandName Invoke-RestMethod { 75 | } -Verifiable -ParameterFilter { $Uri -like 'https://api.telegram.org/bot*getMe*' } 76 | $testBotTokenSplat = @{ 77 | BotToken = $token 78 | } 79 | Test-BotToken @testBotTokenSplat 80 | Assert-VerifiableMock 81 | } #it 82 | 83 | It 'should return a custom PSCustomObject if successful' { 84 | Mock Invoke-RestMethod -MockWith { 85 | [PSCustomObject]@{ 86 | ok = 'True' 87 | result = @{ 88 | id = 2222 89 | is_bot = 'True' 90 | first_name = 'botname' 91 | username = 'botname_bot' 92 | } 93 | } 94 | } #endMock 95 | $testBotTokenSplat = @{ 96 | BotToken = $token 97 | } 98 | $eval = Test-BotToken @testBotTokenSplat 99 | $eval | Should -BeOfType System.Management.Automation.PSCustomObject 100 | $eval.ok | Should -BeExactly 'True' 101 | } #it 102 | } #context_success 103 | } #describe_Test-BotToken 104 | } #inModule 105 | --------------------------------------------------------------------------------