Why is my Telegram bot returning null instead of stock charts?

I’m working on a Telegram bot that’s supposed to return stock charts when given a ticker symbol. But something’s not right. I’ve tweaked some code I found online, adding a function to fetch stock data and plot it. Here’s what I’ve done:

def get_ticker(text):
    stock = f'text'
    start = datetime.date(2000,1,1)
    end = datetime.date.today()
    data = web.DataReader(stock, 'yahoo', start, end)
    plot = data.plot(y='Open')
    return plot

def prepare_data_for_answer(data):
    answer = get_ticker(get_message(data))

    json_data = {
        "chat_id": get_chat_id(data),
        "text": answer
    }

    return json_data

The get_ticker function works fine on its own, but when I use it in the bot, I just get ‘null’ as a response. I’m not sure if I can send charts through the bot or if I’m limited to text. Any ideas on how to fix this? I’m pretty new to this, so I might be missing something obvious. Help would be awesome!

I encountered a similar problem while developing a Telegram bot that was intended to return stock charts. The issue was that Telegram does not accept a plot object directly, which results in a null response. In my case, saving the plot as a PNG file and then using the sendPhoto method resolved the problem. This means you need to adjust your get_ticker function to create an image file instead of returning a plot object. Additionally, take care to remove any temporary files afterwards and handle errors such as invalid ticker symbols or network issues.

Having worked on similar projects, I can confirm that Telegram does not support sending plot objects directly through the bot API. You will need to adjust your approach by saving the generated chart as an image file. After you have created and saved the chart to a temporary location, you can utilize the sendPhoto method to deliver the image. It is important to clean up the temporary file after sending the photo to keep your system tidy. In my experience, altering your get_ticker function to return a file path instead of a plot object and incorporating error handling for invalid tickers or network issues can improve the bot’s performance and robustness.

hey there, i think ur bot can’t send plots directly.
try saving the plot as an image and using sendPhoto to share it.
update ur code accordingly and see if that does the trick!