Microsoft Bot Framework NLP Integration in Mobile Chatbot
Microsoft Bot Framework v4 + Azure Bot Service isn't just NLP, it's a dialog management platform with support for dozens of channels. If your bot needs to work in Teams, Telegram, web chat, and mobile app simultaneously — this is architecturally sound. If you only need mobile — the framework overhead might be excessive.
Where Problems Most Often Arise
Direct Line API. The mobile app connects to Azure Bot Service via Direct Line — a special channel for custom clients. Common mistake: using DirectLineSecret directly in the mobile app. Never do this — the secret is compromised via APK reverse-engineering. Correct approach: backend generates a temporary token via /v3/directline/tokens/generate and gives it to the client. Token lives 30 minutes, refreshable via /v3/directline/tokens/refresh.
// iOS: getting token from server and initializing Direct Line session
func startBotSession() async throws -> String {
let tokenResponse = try await authService.getDirectLineToken()
// Save conversationId for reconnection
UserDefaults.standard.set(tokenResponse.conversationId, forKey: "botConversationId")
return tokenResponse.token
}
LUIS vs CLU. Bot Framework traditionally used LUIS (Language Understanding) for intent recognition. Microsoft is migrating LUIS to Conversational Language Understanding (CLU) under Azure AI Language. For new projects — choose CLU; LUIS is being deprecated. For existing LUIS integration — note that CLU uses different export formats and different SDK (Azure.AI.Language.Conversations).
State Management. Bot Framework stores dialog state in BotState (UserState, ConversationState). By default — in memory, meaning context loss on server restart. In production use CosmosDbPartitionedStorage or BlobStorage:
var storage = new CosmosDbPartitionedStorage(new CosmosDbPartitionedStorageOptions {
CosmosDbEndpoint = configuration["CosmosDb:Endpoint"],
AuthKey = configuration["CosmosDb:AuthKey"],
DatabaseId = "BotStorage",
ContainerId = "DialogState"
});
var userState = new UserState(storage);
var conversationState = new ConversationState(storage);
Adaptive Cards in Mobile Client
Bot Framework supports Adaptive Cards — JSON schema for describing UI cards. Convenient for multi-channel bots: one card renders in Teams, web chat, and your mobile app. Official SDKs exist for iOS and Android (AdaptiveCards-iOS, adaptivecards-android), but style customization is limited — card design doesn't always fit app UI.
In practice, for mobile apps it's often simpler to handle custom activity with type event and render UI natively, ignoring Adaptive Cards.
Direct Line WebSocket vs Polling
Direct Line supports two message retrieval modes: long polling (/v3/directline/conversations/{id}/activities) and WebSocket (streamUrl from session creation response). WebSocket is preferable — reduces latency and server load. On Android — OkHttp WebSocket; on iOS — URLSessionWebSocketTask.
Important: streamUrl lives ~60 seconds without activity, then closes. Handle onClosed and reconnect with refreshed token.
Development Process
Registering Azure Bot Service, setting up Direct Line channel.
Developing bot logic in C# (.NET) or JavaScript/TypeScript (Bot Framework SDK v4).
Integrating CLU/LUIS for intent recognition.
Mobile client: Direct Line token exchange, WebSocket connection, message UI.
Testing via Bot Framework Emulator before Azure deployment.
Timeline Estimates
Integrating with a ready Azure Bot — 3–5 days. Development from scratch including CLU model, dialog logic, Azure infrastructure, and mobile client — 2–4 weeks.







