update modules telegram
This commit is contained in:
parent
aaf946c992
commit
844816c057
3 changed files with 119 additions and 78 deletions
|
|
@ -1,31 +1,50 @@
|
||||||
function Get-FromTelegram {
|
function Get-FromTelegram {
|
||||||
param (
|
param (
|
||||||
$token = "687...:AAF...",
|
$Token = "687...:AAF...",
|
||||||
[switch]$last,
|
[switch]$Date,
|
||||||
[switch]$date
|
[switch]$Last,
|
||||||
)
|
[switch]$ChatID
|
||||||
$endpoint = "getUpdates"
|
)
|
||||||
$url = "https://api.telegram.org/bot$token/$endpoint"
|
$endpoint = "getUpdates"
|
||||||
$result = Invoke-RestMethod -Uri $url
|
$url = "https://api.telegram.org/bot$Token/$endpoint"
|
||||||
if ($date) {
|
$result = Invoke-RestMethod -Uri $url
|
||||||
$Collections = New-Object System.Collections.Generic.List[System.Object]
|
if ($Date) {
|
||||||
foreach ($r in $($result.result)) {
|
$Collections = New-Object System.Collections.Generic.List[System.Object]
|
||||||
|
foreach ($r in $($result.result)) {
|
||||||
$EpochTime = [DateTime]"1/1/1970"
|
$EpochTime = [DateTime]"1/1/1970"
|
||||||
$TimeZone = Get-TimeZone
|
$TimeZone = Get-TimeZone
|
||||||
$UTCTime = $EpochTime.AddSeconds($r.message.date)
|
$UTCTime = $EpochTime.AddSeconds($r.message.date)
|
||||||
$d = $UTCTime.AddMinutes($TimeZone.BaseUtcOffset.TotalMinutes)
|
$d = $UTCTime.AddMinutes($TimeZone.BaseUtcOffset.TotalMinutes)
|
||||||
#$d
|
|
||||||
$Collections.Add([PSCustomObject]@{
|
$Collections.Add([PSCustomObject]@{
|
||||||
Message = $r.message.text;
|
Message = $r.message.text;
|
||||||
Date = $d
|
Date = $d
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
$Collections
|
$Collections
|
||||||
} else {
|
}
|
||||||
if ($last) {
|
else {
|
||||||
|
if ($Last) {
|
||||||
$result.result.message.text[-1]
|
$result.result.message.text[-1]
|
||||||
} else {
|
}
|
||||||
|
elseif ($ChatID) {
|
||||||
|
$Collections = New-Object System.Collections.Generic.List[System.Object]
|
||||||
|
foreach ($r in $($result.result)) {
|
||||||
|
$Collections.Add([PSCustomObject]@{
|
||||||
|
Message = $r.message.text;
|
||||||
|
UserName = $r.message.chat.username;
|
||||||
|
ChatID = $r.message.chat.id;
|
||||||
|
ChatType = $r.message.chat.type
|
||||||
|
})
|
||||||
|
}
|
||||||
|
$Collections
|
||||||
|
}
|
||||||
|
else {
|
||||||
$result.result.message.text
|
$result.result.message.text
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
# Get-FromTelegram
|
||||||
|
# Get-FromTelegram -Last
|
||||||
|
# Get-FromTelegram -Date
|
||||||
|
# Get-FromTelegram -ChatID
|
||||||
|
|
@ -1,14 +1,18 @@
|
||||||
function Send-ToTelegram {
|
function Send-ToTelegram {
|
||||||
param (
|
param (
|
||||||
[Parameter(Mandatory = $True)]$Text,
|
[Parameter(Mandatory = $True)]$Text,
|
||||||
$token = "687...:AAF...",
|
$Token = "687...:AAF...",
|
||||||
$chat = "125468108"
|
$Chat = "125468108",
|
||||||
|
$Keyboard
|
||||||
)
|
)
|
||||||
$endpoint = "sendMessage"
|
$endpoint = "sendMessage"
|
||||||
$url = "https://api.telegram.org/bot$token/$endpoint"
|
$url = "https://api.telegram.org/bot$Token/$endpoint"
|
||||||
$Body = @{
|
$Body = @{
|
||||||
chat_id = $Chat
|
chat_id = $Chat
|
||||||
text = $Text
|
text = $Text
|
||||||
}
|
}
|
||||||
Invoke-RestMethod -Uri $url -Body $Body
|
if ($keyboard -ne $null) {
|
||||||
|
$Body += @{reply_markup = $keyboard}
|
||||||
|
}
|
||||||
|
Invoke-RestMethod -Uri $url -Body $Body
|
||||||
}
|
}
|
||||||
|
|
@ -1,48 +1,66 @@
|
||||||
function Get-FromTelegram {
|
function Get-FromTelegram {
|
||||||
param (
|
param (
|
||||||
$token = "687...:AAF...",
|
$Token = "687...:AAF...",
|
||||||
[switch]$last,
|
[switch]$Date,
|
||||||
[switch]$date
|
[switch]$Last,
|
||||||
)
|
[switch]$ChatID
|
||||||
$endpoint = "getUpdates"
|
)
|
||||||
$url = "https://api.telegram.org/bot$token/$endpoint"
|
$endpoint = "getUpdates"
|
||||||
$result = Invoke-RestMethod -Uri $url
|
$url = "https://api.telegram.org/bot$Token/$endpoint"
|
||||||
if ($date) {
|
$result = Invoke-RestMethod -Uri $url
|
||||||
$Collections = New-Object System.Collections.Generic.List[System.Object]
|
if ($Date) {
|
||||||
foreach ($r in $($result.result)) {
|
$Collections = New-Object System.Collections.Generic.List[System.Object]
|
||||||
|
foreach ($r in $($result.result)) {
|
||||||
$EpochTime = [DateTime]"1/1/1970"
|
$EpochTime = [DateTime]"1/1/1970"
|
||||||
$TimeZone = Get-TimeZone
|
$TimeZone = Get-TimeZone
|
||||||
$UTCTime = $EpochTime.AddSeconds($r.message.date)
|
$UTCTime = $EpochTime.AddSeconds($r.message.date)
|
||||||
$d = $UTCTime.AddMinutes($TimeZone.BaseUtcOffset.TotalMinutes)
|
$d = $UTCTime.AddMinutes($TimeZone.BaseUtcOffset.TotalMinutes)
|
||||||
#$d
|
|
||||||
$Collections.Add([PSCustomObject]@{
|
$Collections.Add([PSCustomObject]@{
|
||||||
Message = $r.message.text;
|
Message = $r.message.text;
|
||||||
Date = $d
|
Date = $d
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
$Collections
|
$Collections
|
||||||
} else {
|
}
|
||||||
if ($last) {
|
else {
|
||||||
|
if ($Last) {
|
||||||
$result.result.message.text[-1]
|
$result.result.message.text[-1]
|
||||||
} else {
|
}
|
||||||
|
elseif ($ChatID) {
|
||||||
|
$Collections = New-Object System.Collections.Generic.List[System.Object]
|
||||||
|
foreach ($r in $($result.result)) {
|
||||||
|
$Collections.Add([PSCustomObject]@{
|
||||||
|
Message = $r.message.text;
|
||||||
|
UserName = $r.message.chat.username;
|
||||||
|
ChatID = $r.message.chat.id;
|
||||||
|
ChatType = $r.message.chat.type
|
||||||
|
})
|
||||||
|
}
|
||||||
|
$Collections
|
||||||
|
}
|
||||||
|
else {
|
||||||
$result.result.message.text
|
$result.result.message.text
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function Send-ToTelegram {
|
function Send-ToTelegram {
|
||||||
param (
|
param (
|
||||||
[Parameter(Mandatory = $True)]$Text,
|
[Parameter(Mandatory = $True)]$Text,
|
||||||
$token = "687...:AAF...",
|
$Token = "687...:AAF...",
|
||||||
$chat = "125468108"
|
$Chat = "125468108",
|
||||||
|
$Keyboard
|
||||||
)
|
)
|
||||||
$endpoint = "sendMessage"
|
$endpoint = "sendMessage"
|
||||||
$url = "https://api.telegram.org/bot$token/$endpoint"
|
$url = "https://api.telegram.org/bot$Token/$endpoint"
|
||||||
$Body = @{
|
$Body = @{
|
||||||
chat_id = $Chat
|
chat_id = $Chat
|
||||||
text = $Text
|
text = $Text
|
||||||
}
|
}
|
||||||
Invoke-RestMethod -Uri $url -Body $Body
|
if ($keyboard -ne $null) {
|
||||||
|
$Body += @{reply_markup = $keyboard}
|
||||||
|
}
|
||||||
|
Invoke-RestMethod -Uri $url -Body $Body
|
||||||
}
|
}
|
||||||
|
|
||||||
$LastDate = (Get-FromTelegram -date)[-1].Date
|
$LastDate = (Get-FromTelegram -date)[-1].Date
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue