This script allows you to send the log of the Chia farmer through the Telegram bot directly to your chat. This will allow you to monitor your farm from any device without your presence. Unfortunately, the script so far only works for Windows, but if this post becomes popular enough, I will make a Linux / Mac OS version as well.
Enable INFO level in farming log
Find and open config with notepad inside file:
“C:\Users\[username]\.chia\mainnet\config\config.yaml”
Look for “farmer:” location, then change “log_level” from “WARNING” to “INFO”. After that you need to restart GUI.
Creating a Bot in Telegram
First of all, we create a bot, which will help us in tracking our progress and the health of the farm. To do this, open the chat and write: /newbot
in the botfather chat using the link or just find by username @botfather .
Also you can change Bot profile photo, description or whatever you need. Just type /help
and get list of all available commands.
Get Chat ID
You also need to get your chat ID. You can rerieve it from API or from @chatid_echo_bot and type /start
.
Creating of Powershell Script
Now, it’s time to create Powershell Script. You can do it using notepad or whatever soft you want. Just paste this content to new file with name telegram-bot.ps1:
$id = "YOUR CHAT ID FROM TELEGRAM"
$bot_token = "YOUR TELEGRAM BOT TOKEN"
do {
$message = gc "$env:USERPROFILE\.chia\mainnet\log\debug.log" | Select-String -Pattern '(?<!\s0\s)plots were eligible for farming' | Select-Object -Last 1
$message -match "(.*) harvester .*(\d) plots .* farming (.*)\.\.\. Found (\d) .*me: (.*) s\. Total (.*) plots"
$plottime = [datetime]::ParseExact($Matches.1, "yyyy'-'MM'-'dd'T'HH':'mm':'ss.fff", $null)
$now = (Get-Date).AddSeconds(-5)
if($plottime -gt $now)
{
$time = $Matches.5 -as [float]
if($time -gt 5)
{
$status = '🔴'
} elseif($time -gt 1) {
$status = '🟡'
} else {
$status = '🟢'
}
if ($Matches.4 -gt 0)
{
$status = '✔️'
}
$text = $status + ' 🌱 ' + $Matches.2 + ' / ' + $Matches.6 + ' 🔍 ' + $Matches.4 + ' ⏱️ ' + $Matches.5
$uri = "https://api.telegram.org/bot$bot_token/sendMessage"
Invoke-WebRequest -Method Post -Uri $uri -ContentType "application/json;charset=utf-8" `
-Body (ConvertTo-Json -Compress -InputObject @{chat_id=$id; text=$text})
}
} until (Start-Sleep -Seconds 5)
Create shortcut, to start this script from powershell and paste:
C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -noexit -windowstyle hidden -File “C:\YOUR SCRIPT LOCATION\Telegram-bot.ps1″
That’s it, after you run this shortcut, bot will start send you formatted messages about found plots, proofs and spent time. Console will start hidden, but you can stop it from powershell:
Get-WmiObject -Class win32_process -Filter "name='powershell.exe'" | Select-Object -Property ProcessId, CommandLine
stop-process PID
First circle – status of attempted proof:
- 🟢 – everything is ok, but no proofs found
- 🟡 – warning, proof spent time greater than 1 second
- 🔴 – troubles with connection or hdd cause time more than 5 seconds on proof
Debug section
If you have issues with this guide, try:
Download source code directly and change extension to .ps1
Open Powershell and check if log return data with this command:
gc “$env:USERPROFILE\.chia\mainnet\log\debug.log” -Wait | Select-String -Pattern ‘(?
If everything ok, try start script with administator permissions.
If you have some improvements or ideas, please, write it to comments! Thank you for reading and good luck in farming.
Hi, I get this error when runnning the bot:
Invoke-WebRequest : {“ok”:false,”error_code”:400,”description”:”Bad Request: message text is empty”}
At C:\Users\XXX\Desktop\telegram-bot.ps1:49 char:1
+ Invoke-WebRequest -Method Post -Uri $uri -ContentType “application/js …
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-WebRequest], WebExc
eption
+ FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeWebRequestCommand
-Body : The term ‘-Body’ is not recognized as the name of a cmdlet, function, script file, or operable program. Check
the spelling of the name, or if a path was included, verify that the path is correct and try again.
At C:\Users\Pythagoras\Desktop\telegram-bot.ps1:51 char:1
+ -Body (ConvertTo-Json -Compress -InputObject @{chat_id=$id; text=$tex …
+ ~~~~~
+ CategoryInfo : ObjectNotFound: (-Body:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
What I’m missing?
Is it running with Administration rights? Can you open Powershell and type:
gc “$env:USERPROFILE\.chia\mainnet\log\debug.log” -Wait | Select-String -Pattern ‘(?
Thank you for your response.
Yes, if I run this command alone I receive the output from the log file..
I added source code in TXT file, try download it and rename to PS1 https://interchargers.com/wp-content/uploads/2021/05/telegram-chia.txt
Thank you, that worked, the message reached the bot. It may be related to the icons being used, since Powershell ISE asked me to re-encode them.
However, despite it working, I got another error:
Invoke-WebRequest : The response content cannot be parsed because the Internet Explorer engine is not available, or
Internet Explorer’s first-launch configuration is not complete. Specify the UseBasicParsing parameter and try again.
At C:\Users\Pythagoras\Desktop\telegram-chia.ps1:30 char:1
+ Invoke-WebRequest -Method Post -Uri $uri -ContentType “application/js …
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotImplemented: (:) [Invoke-WebRequest], NotSupportedException
+ FullyQualifiedErrorId : WebCmdletIEDomNotSupportedException,Microsoft.PowerShell.Commands.InvokeWebRequestComman
d
Ok, I also add to run Explorer on that machine for the first time – no errors then. Thank you so much for your guide and assistance, I hope the bot will receive more features as well as support for other OSes 😉
error 404, entered all data correctly
I added Debug section to article, try download source code directly
hello !
I have same error
Read the debug section or download source code directly” rel=”noopener” target=”_blank”>download script directly and rename with .ps1 extension
Invoke-WebRequest : {“ok”:false,”error_code”:400,”description”:”Bad Request: chat not found”}
строка:30 знак:1
+ Invoke-WebRequest -Method Post -Uri $uri -ContentType “application/js …
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-WebRequest], WebException
+ FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeWebRequestCommand
I download source code, but i have problem error 400
Your chat id is wrong, check it.
Same problem here: ( ID is correct )
Invoke-WebRequest : {“ok”:false,”error_code”:400,”description”:”Bad Request: chat not found”}
At D:\telegram-bot.ps1:30 char:1
+ Invoke-WebRequest -Method Post -Uri $uri -ContentType “application/js …
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-WebRequest], WebExc
eption
+ FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeWebRequestCommand
Read error, your chat ID not found, is ID correct?
ubuntu pls 🙂
yes please 🙂
Hello,
I get this error:
Exception calling “ParseExact” with “3” argument(s): “A karakterlánc nem értelmezhető érvényes DateTime érték
ként.” ( Translate: “String was not recognized as a
valid DateTime.” )
At C:\Users\………\telegram-bot.ps1:7 char:1
+ $plottime = [datetime]::ParseExact($Matches.1, “yyyy’-‘MM’-‘dd”, $nul …
Can you help me?
Thank You!
Did you try to run command from powershell? What data do you get? Looks like datetime from log file did not match datetime template from script.
Hi Op, just executed on power shell ISE, and console just print true but i dont get any massage from bot in smartphone.
Everything OK. You probably have small amount of plots. Wait for a while. Or check if your log is working with method from “Debug section of article”.
Thank you!
bot running well, but instead icons i see strange letters like: “dźź~”
any idea how to solve that?
Try reload script and save it UTF-8 without BOM
Emoticons don’t work for me either, I tried in every way and saving the file as recommended but nothing to do …
Invoke-WebRequest : {“ok”:false,”error_code”:404,”description”:”Not Found”}
No C:\ChiaKey\telegram-bot.ps1:30 caractere:1
+ Invoke-WebRequest -Method Post -Uri $uri -ContentType “application/js …
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-WebRequest], WebExc
eption
+ FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeWebRequestCommand
Reload raw version of code from debug section.
Hello,
I downloaded the source code but I have an error :
Invoke-WebRequest : {“ok”:false,”error_code”:401,”description”:”Unauthorized”}
Au caractère Ligne:30 : 1
+ Invoke-WebRequest -Method Post -Uri $uri -ContentType “application/js …
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation : (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-WebRequest], WebException
+ FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeWebRequestCommand
Can you help me?
Thank You!
You got auth errors, try recheck your bot token