OpenAI Assistant API and Telegram bot

I am trying to build a Telegram bot powered by an Assistant. Right now I have something that works but for whatever reason refuses to use function calling even if locally the function works. Is there a Github project that supports function calling on Telegram? Reading someone else solution would greatly help me solve this problem

Telegram does not effect what your code can do or does telegram bots are basicly just a frontend to your code in the backend kind of like a website you define a event filter for something happening extract if needed the data and serve a response to it

Which language and wrapper are you using
And are you building a client so a userbot or a normal bot

I have used this as starting point: efelem/telegram_openai_assistant on github

import openai as client
import ipdb
import time
import sys

# Replace 'your-assistant-id' with the Assistant ID from OpenAI's platform
assistant_id = ""
# Replace 'your-api-key' with your actual API key
client.api_key = ""

def next_move(action: str) -> str:
    if action == "Action B":
        return "Generate Action B relate"
    if action == "Action A":
        return "Generate Action A related"
        return "No action. Ask the user to clarify"

thread = client.beta.threads.create()

message_str = " ".join(sys.argv[1:])

message = client.beta.threads.messages.create(, role="user", content=message_str

# Step 4: Run the Assistant
run = client.beta.threads.runs.create(,


while True:
    # Wait for 5 seconds

    # Retrieve the run status
    run_status = client.beta.threads.runs.retrieve(,

    # If run is completed, get messages
    if run_status.status == 'completed':
        messages = client.beta.threads.messages.list(

        # Loop through messages and print content based on role
        for msg in
            role = msg.role
            content = msg.content[0].text.value
            print(f"{role.capitalize()}: {content}")

    elif run_status.status == 'requires_action':
        print("Function Calling")
        required_actions = run_status.required_action.submit_tool_outputs.model_dump()
        tool_outputs = []
        import json
        for action in required_actions["tool_calls"]:
            func_name = action['function']['name']
            arguments = json.loads(action['function']['arguments'])
            if func_name == "next_move":
                output = next_move(action=arguments['action'])
                    "tool_call_id": action['id'],
                    "output": output
                raise ValueError(f"Unknown function: {func_name}")
        print("Submitting outputs back to the Assistant...")
        print("Waiting for the Assistant to process...")

messages = client.beta.threads.messages.list(


this is the function

  "name": "next_move",
  "description": "Get the next move",
  "parameters": {
    "type": "object",
    "properties": {
      "action": {
        "type": "string",
        "description": "the action the user is requesting"
    "required": [

The text in the function if statement is stub and the telegram bot hangs on Requires action.