.net 通过电报机器人发送文件
需要多部分/表单数据.net 通过电报机器人发送文件,.net,powershell,telegram,telegram-bot,.net,Powershell,Telegram,Telegram Bot,需要多部分/表单数据 $path = 'C:\file.txt' $userId = 12345 $token = "ABC123" $url = "https://api.telegram.org/-/sendDocument?chat_id=+" [net.servicepointmanager]::securityprotocol = 'ssl3,tls,tls11,tls12' $url = $url.Replace(&quo
$path = 'C:\file.txt'
$userId = 12345
$token = "ABC123"
$url = "https://api.telegram.org/-/sendDocument?chat_id=+"
[net.servicepointmanager]::securityprotocol = 'ssl3,tls,tls11,tls12'
$url = $url.Replace("-",$token).Replace("+",$userId)
$Response = Iwr -Uri $url -Method Post -InFile $path -ContentType "multipart/form-data"
$Response.Content
但是我得到了错误:400。如何正确地发送文件?我对它了解不多,但我最近在电报上读到一些东西,我知道有一个叫做PoShGram的模块,可以让你与它进行交互。你可以找到它 乍一看,它可能具有您需要的功能。读我的书说: 本项目的目标是将复杂性抽象出来,以利于 简单而直接的PowerShell命令
我对它了解不多,但我最近在电报上读到了一些东西,我知道有一个叫做PoShGram的模块,可以让你和它互动。你可以找到它 乍一看,它可能具有您需要的功能。读我的书说: 本项目的目标是将复杂性抽象出来,以利于 简单而直接的PowerShell命令
通过PowerShell使用电报机器人发送文件需要更多的工作。 这是如何发送文本文档的示例:
$payload = @{
chat_id = $ChatID
document = $FileURL
caption = $Caption
parse_mode = $ParseMode
disable_notification = $DisableNotification.IsPresent
}
$invokeRestMethodSplat = @{
Uri = ("https://api.telegram.org/bot{0}/sendDocument" -f $BotToken)
Body = (ConvertTo-Json -Compress -InputObject $payload)
ErrorAction = 'Stop'
ContentType = "application/json"
Method = 'Post'
}
try {
Invoke-RestMethod @invokeRestMethodSplat
}
catch {
Write-Error $_
}
我发现的另一个选项是使用PowerShellV6.1或更高版本中的表单
param(如果需要,可以从GitHub获得);我发现了这个原始的例子:
通过PowerShell使用电报机器人发送文件需要更多的工作。 这是如何发送文本文档的示例:
$payload = @{
chat_id = $ChatID
document = $FileURL
caption = $Caption
parse_mode = $ParseMode
disable_notification = $DisableNotification.IsPresent
}
$invokeRestMethodSplat = @{
Uri = ("https://api.telegram.org/bot{0}/sendDocument" -f $BotToken)
Body = (ConvertTo-Json -Compress -InputObject $payload)
ErrorAction = 'Stop'
ContentType = "application/json"
Method = 'Post'
}
try {
Invoke-RestMethod @invokeRestMethodSplat
}
catch {
Write-Error $_
}
我发现的另一个选项是使用PowerShellV6.1或更高版本中的表单
param(如果需要,可以从GitHub获得);我发现了这个原始的例子: