1. Anuncie Aqui ! Entre em contato fdantas@4each.com.br

[Python] How to make specific text bold in the output of my Telegram bot?

Discussão em 'Python' iniciado por Stack, Outubro 4, 2024 às 07:42.

  1. Stack

    Stack Membro Participativo

    I'm working on a Telegram bot and I want to make certain parts of the text bold in the response when providing the profile context of a site. Here’s a snippet of my code that retrieves and formats the site profile:

    def get_profile_context(site_name):
    """Find the profile context based on the site name, case-insensitive."""
    site_name = site_name.lower()
    site_info = site_data[site_data['site_name'].str.lower() == site_name]

    if not site_info.empty:
    row = site_info.iloc[0]
    context = (
    f"- Enodeb ID: *{row['enodeb_id']}*\n"
    f"- Site ID: {row['site_id']}\n"
    f"- MC: {row['mc']}\n"
    f"- TAC: {row['tac']}\n"
    f"- Region: {row['region']}\n"
    f"- Regency: {row['regency']}\n"
    f"- Antenna Height: {row['antenna_height']}\n"
    f"- Azimuth: {row['azimuth']}\n"
    )
    print(context)
    global context_global
    context_global = context
    return context
    else:
    return "Site name not found."

    async def button(update: Update, context: ContextTypes.DEFAULT_TYPE):
    query = update.callback_query
    await query.answer()

    if query.data == 'profile_site':
    profile_context = get_profile_context(status["site_name"])
    await query.edit_message_text(f"Profile of site '{status['site_name']}':\n{profile_context}")
    keyboard = [
    [InlineKeyboardButton("Back to Menu", callback_data='back_to_menu'),
    InlineKeyboardButton("Back to Start", callback_data='start')]
    ]
    reply_markup = InlineKeyboardMarkup(keyboard)
    await query.message.reply_text("What would you like to do next?", reply_markup=reply_markup)



    In the output, I want the site name (e.g., "Profile of site 'site_name'") to be bold. However, when I use the * symbols around the text, it doesn't seem to work. How can I properly format this text to make it bold in the message sent by the bot?

    i want to the answer is bold :

    Profile of site'--':

    • Enodeb ID: 0000
    • Site ID: 000000
    • MC: MC
    • TAC: 00
    • Region: NORTH CENTRAL
    • Regency: city
    • Antenna Height: 61
    • Azimuth: 3_0

    Continue reading...

Compartilhe esta Página