Reputation: 556
I'm having an issue with a teams chat bot application that is trying to send a proactive message to let users know their password is expiring. The app is created using the teams toolkit in Nodejs and runs from the an azure function like they do. This all works fine.
The problem comes in when the app gets updated and redeployed. For some reason after updating the app it is no longer able to send a message to any users unless they first engage with the app by sending it a message first. This is obviously not a good solution; we can't have every user in our organization find the app in teams and send it "hello".
What is the recommended way to handle this situation? How do you update a chat bot app without losing the ability to send a message?
Upvotes: 1
Views: 76
Reputation: 3619
The issue you're experiencing is related to notification connections storage in your Teams bot. When your app gets updated and redeployed, the default storage for these connections is being wiped out, which is why your bot can't send proactive messages until users engage with it again.
This happens because the default local file storage used by Teams bots stores notification connections in:
.notification.localstore.json
if running locally${process.env.TEMP}/.notification.localstore.json
if running on AzureAs mentioned in the documentation, Azure web apps and Azure Functions clean up local files during restarts or redeploys, which is exactly why your connections are being lost.
Solution would be to implement custom persistent storage. Create a custom storage class that implements the NotificationTargetStorage
interface:
// implement your own storage class
class MyPersistentStorage implements NotificationTargetStorage {
// Implementation for database of your choice
async read(key: string): Promise<any> {
// Read connection from your database
}
async write(key: string, data: any): Promise<void> {
// Write connection to your database
}
async delete(key: string): Promise<void> {
// Delete connection from your database
}
async list(): Promise<string[]> {
// List all connection keys from your database
}
}
You can implement this storage using any persistent storage, preferrably a NoSQL because the data is in JSON format/unstructured. You can cross-verify with the content of the .notification.localstore.json
file on your local development machine.
Upvotes: 0