Project 11-telegram message- syntax error

I am getting a syntax error everytime i try to run the code for sensing a message via telegram
Here is the code:

And this is the error:

Try the below code, name it

   bolt_api_key = "XXXXXXXXXXXXXX"                 # This is your Bolt Cloud API Key
device_id = "BOLTXXXXXXX"                    # This is the device ID and will be similar to BOLTXXXX where XXXX is some numbers
telegram_chat_id = "@XXXXXX"            # This is the channel ID of the created Telegram channel. Paste after @ symbol.
telegram_bot_id = "botXXXXXXX"           # This is the bot ID of the created Telegram Bot. Paste after bot text.
threshold = 300                    # Threshold beyond which the alert should be sent

here is the complete code , name it

import requests # for making HTTP requests
import json # library for handling JSON data
import time # module for sleep operation

from boltiot import Bolt # importing Bolt from boltiot module
import conf # config file

mybolt = Bolt(conf.bolt_api_key, conf.device_id)

def get_sensor_value_from_pin(pin):
“”“Returns the sensor value. Returns -999 if request fails”""
response = mybolt.analogRead(pin)
data = json.loads(response)
if data[“success”] != 1:
print(“Request not successfull”)
print(“This is the response->”, data)
return -999
sensor_value = int(data[“value”])
return sensor_value
except Exception as e:
print(“Something went wrong when returning the sensor value”)
return -999

def send_telegram_message(message):
“”“Sends message via Telegram”""
url = “” + conf.telegram_bot_id + “/sendMessage”
data = {
“chat_id”: conf.telegram_chat_id,
“text”: message
response = requests.request(
print(“This is the Telegram URL”)
print(“This is the Telegram response”)
telegram_data = json.loads(response.text)
return telegram_data[“ok”]
except Exception as e:
print(“An error occurred in sending the alert message via Telegram”)
return False

while True:
# Step 1
sensor_value = get_sensor_value_from_pin(“A0”)
print(“The current sensor value is:”, temp)

# Step 2
if sensor_value == -999:
    print("Request was unsuccessfull. Skipping.")

# Step 3
if sensor_value >= conf.threshold:
    print("Sensor value has exceeded threshold")
    message = "Alert! Sensor value has exceeded " + str(conf.temp_threshold) + \
              ". The current value is " + str(temp)
    telegram_status = send_telegram_message(message)
    print("This is the Telegram status:", telegram_status)

# Step 4

If you are facing difficulties in the channel id and bot id part,please search in bolt forum.You will find the required solution.

Hope this helps ! :slight_smile:

you have missed to use the brackets after double quotes and to use string function str(sensor_value)

I got it, thank you :))) I had missed the bracket in print command.

Thank you so muchh :))