A Teams bot to let you chat with ChatGPT on Teams.
- Install Node.js: Node.js (nodejs.org)
- Install Git: Git for Windows
- Install VS Code: Visual Studio Code - Code Editing. Redefined
- Install Azure Function Extension on VSCode
In VSCode, go to extensions and search Azure Function to isntall it:
- Ensure you have a Microsoft 365 account and follow the Teams development document to register an App with bot feature.
Ensure the below permissions are set and you can add a command to allow users to delete chat history.
Please note the bot id and create a client secret which will be used in later.
Bot Id/MicrosoftAppId
You can go to Tools in Teams Developer portal to find the bot you created.
Client Secret/MicrosoftAppPassword
And create a new client secret.
- Ensure you have an Azure subscription to create these resources in one resource group:
- Azure OpenAI resource and deployments: https://learn.microsoft.com/en-us/azure/ai-services/openai/how-to/create-resource?pivots=web-portal
- Azure Storage account: https://learn.microsoft.com/en-us/azure/storage/common/storage-account-create?tabs=azure-portal
- Azure CosmosDB for Mongo: https://learn.microsoft.com/en-us/azure/cosmos-db/mongodb/quickstart-dotnet?tabs=azure-portal%2Cwindows#create-an-azure-cosmos-db-account
-
Open Terminal and clone the project:
git clone https://github.com/yangsa666/node-js-teams-bot-with-chatgpt.git
. -
Open the project folder with VS Code.
-
Raname
local.samplesettings.json
tolocal.settings.json
, fill the required information. In this sample, it uses MongoDb to store user's chat history with ChatGPT. If you don't have a MongoDb, you can create one on Azure for test.
AzureWebJobsStorage
: Azure storage account connection string. Create a storage account in Azure Portal and go to Access Key to copy a connection string.
MicrosoftAppTenantId
: Your Azure AD / MIcrosoft Entra Tenant ID.
MicrosoftAppId
: Bot Id of the bot you created previously.
MicrosoftAppPassword
: Client secret of the bot you created previously.
OPENAI_API_KEY
: Your OpenAI API key.
OpenAI_MODEL
: Your OpenAI model
MongoDb_Connection_String
: The connectionstring of the Azure CosmosDB for Mongo you created previously.
-
Open Azure Functions Extension, sign in your Azure subscription account to deploy it in the resource group you created before and upload settings to Azure Functions App. See more details here.
!!!Note!!! If you're using Azure Open AI API, please switch to
AzureOpenAIStack
branch. You can switch branch via the steps below in VSCode. -
After deploying it, configure the Azure function URL in the Teams bot Endpoint URL in Teams developer portal. You can get Azure Function URL by going to Azure Portal, locate your function app you created in the steps above. Then go to messages function, click
Get Function Url
button.Then you can go back to Teams Developer portal > Tools > find the bot you created > Configure. In the endpoint address field, fill the Azure Function Url you got. NOTE: Please remove
?
in the endpoint address. -
Install or preview the Teams bot app on your teams To export the installation package, you can go to Teams Developer portal > locate your app > Publish > Download the app package.
Then you can go to Teams to upload this as a custom app. Reference: https://learn.microsoft.com/en-us/microsoftteams/platform/concepts/deploy-and-publish/apps-upload
-
Enjoy it by saying hello to the bot.