User Tools

Site Tools


wiki:ai:azure_chatbot_with_open_ai_integration

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Next revision
Previous revision
wiki:ai:azure_chatbot_with_open_ai_integration [2025/06/27 16:38] – created ymurugesanwiki:ai:azure_chatbot_with_open_ai_integration [2025/07/10 21:40] (current) ymurugesan
Line 16: Line 16:
  
  
 +On the Azure side create the below
 +
 +1. Azure Open AI service - Obtain the key, endpoint and the deployment name.
 +2. Create a new  Azure bot from the bot service with multi tenant ( single tenant does not work but multi tenant is out of support after july end. Have to investigate what could be the workaround)
 +
 +Env variables
 +
 +AZURE_OPENAI_ENDPOINT=
 +AZURE_OPENAI_KEY=2
 +AZURE_OPENAI_DEPLOYMENT_NAME=
 +PORT=3978
 +
 +Save above env variables as .env
 +
 +To run in local
 +<code>
 + npm init -y
 +npm install botbuilder restify dotenv openai
 +npm install --save-dev nodemon
 +npm install -g ngrok
 +
 +ngrok http 3978 -- To run ngrok
 +
 +</code>
 +
 +Once you got the ngrok url update it in configuration in the Azure Bot service
 +
 +
 +===== package.json =====
 +
 +<code>
 +
 +{
 +  "scripts": {
 +    "start": "node index.js",
 +    "dev": "nodemon index.js"
 +  }
 +}
 +
 +
 +
 +</code> 
  
 ===== Bot.js ===== ===== Bot.js =====
Line 419: Line 461:
 </code> </code>
  
 +
 +
 +**
 +
 +To run in Azure**
 +
 +1. Create a webapp in azure ( without database) (Node 20 with windows)
 +
 +2. Add all the env variables below in the azure webapp. Do not zip the env variables
 +
 +3. Add the below web.config
 +
 +
 +<code>
 +
 +<configuration>
 +  <system.webServer>
 +    <handlers>
 +      <add name="iisnode" path="index.js" verb="*" modules="iisnode"/>
 +    </handlers>
 +    <rewrite>
 +      <rules>
 +        <rule name="Node.js" stopProcessing="true">
 +          <match url=".*"/>
 +          <action type="Rewrite" url="index.js"/>
 +        </rule>
 +      </rules>
 +    </rewrite>
 +  </system.webServer>
 +</configuration>
 +
 +</code>
 +
 +4. Update the package.json
 +
 +<code>
 +
 +{
 +  "name": "azure-openai-bot",
 +  "version": "1.0.0",
 +  "description": "Azure OpenAI Bot with Slack integration",
 +  "main": "index.js",
 +  "engines": {
 +    "node": "22.x",
 +    "npm": ">=9.0.0"
 +  },
 +  "scripts": {
 +    "start": "node index.js",
 +    "dev": "nodemon index.js"
 +  },
 +  "keywords": [
 +    "azure",
 +    "openai",
 +    "bot",
 +    "slack",
 +    "chatbot"
 +  ],
 +  "author": "",
 +  "license": "ISC",
 +  "type": "commonjs",
 +  "dependencies": {
 +    "@azure/core-auth": "^1.9.0",
 +    "@azure/openai": "^2.0.0",
 +    "@slack/web-api": "^7.9.3",
 +    "botbuilder": "^4.17.0-blobs1",
 +    "dotenv": "^16.5.0",
 +    "openai": "^5.7.0",
 +    "restify": "^11.1.0"
 +  },
 +  "devDependencies": {
 +    "nodemon": "^3.1.10"
 +  }
 +}
 +
 +
 +</code>
 +
 +5. Zip the contents
 +
 +6. Deploy using CLI 
 +
 +<code>
 +az webapp deploy --resource-group xxx --name xx --src-path deployment123.zip --type zip 
 +
 +</code>
 +
 +7. Verify the log stream for deployment logs to ensure deployment succeeds
 +
 +
 +
 +
 +{{:wiki:ai:screenshot_2025-07-10_at_4.35.02 pm.png?600|}}
wiki/ai/azure_chatbot_with_open_ai_integration.1751042306.txt.gz · Last modified: by ymurugesan