I’m working on a C# application and need to implement direct messaging functionality through a Telegram bot. Currently, I can only find examples for posting messages to channels or groups where the bot has admin permissions.
My goal is to create a system that can send private notifications directly to individual users when they’re active in my application. I also want to build a two-way communication system where users can send specific commands back to the bot to trigger certain actions in my system, like creating new user accounts (with proper admin verification, of course).
Is it possible to send personal messages to users through a Telegram bot using C#? What approach should I take for this kind of direct user communication?
Yes, you can send direct messages with a C# Telegram bot, but here’s the catch that gets most developers: users have to message your bot first. Telegram won’t let bots start conversations with people who haven’t contacted them.
I’ve built this feature in several projects using the Telegram.Bot NuGet package. Here’s how it works: save user chat IDs when they first interact with your bot, then use SendTextMessageAsync() to message those chat IDs later.
For two-way communication, set up webhook handling or use long polling to receive and process incoming messages. Pro tip I learned the hard way - add error handling for blocked users and deleted chats. These throw exceptions when you try sending messages.
Also consider adding a user registration flow where people can link their app account to their Telegram chat ID using verification codes.
Pretty straightforward once you get the permission model. I built this for production last year with TelegramBotClient from the official package. You’ll need to store chat IDs in your database when users first contact your bot. Then just use SendTextMessageAsync with their chat ID to message them directly. The tricky bit is onboarding - I set up a /start command that creates verification tokens to link app accounts with Telegram profiles. For commands, I just used a message handler with simple string matching for stuff like /create or /status. No need to overcomplicate the parsing. Always validate permissions before letting users do sensitive stuff like creating accounts. One thing that bit me: rate limiting is brutal with direct messages. Telegram’s really strict about message frequency, so you’ll want queuing if you’re sending bulk notifications.
Yeah, bots need users to message first, but here’s what I do: create a deep link like Telegram: Contact @yourbotname and send it through email or embed it in your app. When they click it, Telegram opens with your bot and fires off the start command with their token automatically. Totally sidesteps that whole “user must message first” thing. Just make sure you’re generating unique tokens for each user and validating them server-side when the /start command hits.