Chia Telegram Bot for Log notifications from Powershell

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 .

Create Telegram Bot Chia XCH Coin

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.

Get Chat Id Telegram

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″

Chia Crypto Coin Bot for Telegram

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.

27 thoughts on “Chia Telegram Bot for Log notifications from Powershell”

  1. 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?

    Reply
    • Is it running with Administration rights? Can you open Powershell and type:

      gc “$env:USERPROFILE\.chia\mainnet\log\debug.log” -Wait | Select-String -Pattern ‘(? Reply

          • 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 😉

      • 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

        Reply
          • 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

  2. 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!

    Reply
  3. Hi Op, just executed on power shell ISE, and console just print true but i dont get any massage from bot in smartphone.

    Reply
    • 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”.

      Reply
  4. 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

    Reply
  5. 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!

    Reply

Leave a Reply to chargeme Cancel reply