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"
    else:
        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(
    thread_id=thread.id, role="user", content=message_str
)

# Step 4: Run the Assistant
run = client.beta.threads.runs.create(
    thread_id=thread.id,
    assistant_id=assistant_id,
)

print(run.model_dump_json(indent=4))

while True:
    # Wait for 5 seconds
    time.sleep(5)

    # Retrieve the run status
    run_status = client.beta.threads.runs.retrieve(
        thread_id=thread.id,
        run_id=run.id
    )
    print(run_status.model_dump_json(indent=4))

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

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

        break
    elif run_status.status == 'requires_action':
        print("Function Calling")
        required_actions = run_status.required_action.submit_tool_outputs.model_dump()
        print(required_actions)
        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'])
                print(output)
                tool_outputs.append({
                    "tool_call_id": action['id'],
                    "output": output
                })
            else:
                raise ValueError(f"Unknown function: {func_name}")
            
        print("Submitting outputs back to the Assistant...")
        client.beta.threads.runs.submit_tool_outputs(
            thread_id=thread.id,
            run_id=run.id,
            tool_outputs=tool_outputs
        )
    else:
        print("Waiting for the Assistant to process...")
        time.sleep(5)


messages = client.beta.threads.messages.list(thread_id=thread.id)

print(messages.dict()["data"][0]["content"][0]["text"]["value"])

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": [
      "action"
    ]
  }
}

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