From 3d26bea0493ec8f2366adb794abb349a648b38af Mon Sep 17 00:00:00 2001
From: Ning Tang <nintan@microsoft.com>
Date: Thu, 9 Jan 2025 06:20:20 +0800
Subject: [PATCH] [JS] fix: local debug environment variables location in teams
 chef bot sample (#2240)

## Linked issues

closes: #2241

## Details

Provide a list of your changes here. If you are fixing a bug, please
provide steps to reproduce the bug.
1. Fix bug that debugging in test tool is not working after local
debugging.
  a. Clone the sample.
  b. Select "Debug (Edge)" and press "F5".
  c. Stop debugging and Select "Debug in Test Tool".
  d. The Test Tool will show authentication error.
2. Fix the outdated lines in README file.

#### Change details

Environment variables like bot id and password will be read from
.localConfigs in npm script.
So the env file update in teamsapp.local.yml should be ".localConfigs".
Writing to ".env" file will pollute the Test Tool environment.

> Describe your changes, with screenshots and code snippets as
appropriate

**code snippets**:

**screenshots**:

## Attestation Checklist

- [ ] My code follows the style guidelines of this project

- I have checked for/fixed spelling, linting, and other errors
- I have commented my code for clarity
- I have made corresponding changes to the documentation (updating the
doc strings in the code is sufficient)
- My changes generate no new warnings
- I have added tests that validates my changes, and provides sufficient
test coverage. I have tested with:
  - Local testing
  - E2E testing in Teams
- New and existing unit tests pass locally with my changes

### Additional information

> Feel free to add other relevant information below

---------

Co-authored-by: Corina <14900841+corinagum@users.noreply.github.com>
---
 js/samples/04.ai-apps/a.teamsChefBot/README.md        |  4 ++--
 js/samples/04.ai-apps/a.teamsChefBot/package.json     |  1 -
 js/samples/04.ai-apps/a.teamsChefBot/src/index.ts     | 11 +++--------
 .../04.ai-apps/a.teamsChefBot/teamsapp.local.yml      |  2 +-
 4 files changed, 6 insertions(+), 12 deletions(-)

diff --git a/js/samples/04.ai-apps/a.teamsChefBot/README.md b/js/samples/04.ai-apps/a.teamsChefBot/README.md
index 1788d48d83..eef1937add 100644
--- a/js/samples/04.ai-apps/a.teamsChefBot/README.md
+++ b/js/samples/04.ai-apps/a.teamsChefBot/README.md
@@ -60,8 +60,8 @@ If you are using Azure OpenAI then follow these steps:
         AZURE_OPENAI_ENDPOINT: ${{SECRET_AZURE_OPENAI_ENDPOINT}}
 ```
 
-- Open `./infra/azure.bicep` and comment out lines 72-75 and uncomment lines 76-83.
-- Open `./infra/azure.parameters.json` and replace lines 20-22 with:
+- Open `./infra/azure.bicep` and comment out lines of 'OPENAI_KEY' section and uncomment lines of 'AZURE_OPENAI_KEY' and 'AZURE_OPENAI_ENDPOINT' sections.
+- Open `./infra/azure.parameters.json` and replace lines of "openAIKey" section with:
 
 ```json
       "azureOpenAIKey": {
diff --git a/js/samples/04.ai-apps/a.teamsChefBot/package.json b/js/samples/04.ai-apps/a.teamsChefBot/package.json
index e4fbcd1586..57b988b628 100644
--- a/js/samples/04.ai-apps/a.teamsChefBot/package.json
+++ b/js/samples/04.ai-apps/a.teamsChefBot/package.json
@@ -25,7 +25,6 @@
         "@microsoft/teams-ai": "~1.7.2",
         "@microsoft/teams-js": "^2.32.0",
         "botbuilder": "^4.23.1",
-        "dotenv": "^16.4.5",
         "openai": "4.77.4",
         "replace": "~1.2.0",
         "restify": "~11.1.0",
diff --git a/js/samples/04.ai-apps/a.teamsChefBot/src/index.ts b/js/samples/04.ai-apps/a.teamsChefBot/src/index.ts
index d6e5783c32..3da0ef8ff3 100644
--- a/js/samples/04.ai-apps/a.teamsChefBot/src/index.ts
+++ b/js/samples/04.ai-apps/a.teamsChefBot/src/index.ts
@@ -2,7 +2,6 @@
 // Licensed under the MIT License.
 
 // Import required packages
-import { config } from 'dotenv';
 import * as path from 'path';
 import * as restify from 'restify';
 
@@ -11,22 +10,18 @@ import * as restify from 'restify';
 import { ConfigurationServiceClientCredentialFactory, MemoryStorage, TurnContext } from 'botbuilder';
 
 import {
+    ActionPlanner,
     AI,
     Application,
-    ActionPlanner,
     OpenAIModel,
     PromptManager,
-    TurnState,
-    TeamsAdapter
+    TeamsAdapter,
+    TurnState
 } from '@microsoft/teams-ai';
 
 import { addResponseFormatter } from './responseFormatter';
 import { VectraDataSource } from './VectraDataSource';
 
-// Read botFilePath and botFileSecret from .env file.
-const ENV_FILE = path.join(__dirname, '..', '.env');
-config({ path: ENV_FILE });
-
 // Create adapter.
 // See https://aka.ms/about-bot-adapter to learn more about how bots work.
 const adapter = new TeamsAdapter(
diff --git a/js/samples/04.ai-apps/a.teamsChefBot/teamsapp.local.yml b/js/samples/04.ai-apps/a.teamsChefBot/teamsapp.local.yml
index 71f1d5a54b..8bf56bc201 100644
--- a/js/samples/04.ai-apps/a.teamsChefBot/teamsapp.local.yml
+++ b/js/samples/04.ai-apps/a.teamsChefBot/teamsapp.local.yml
@@ -50,7 +50,7 @@ deploy:
     # Provides the Teams Toolkit .env file values to the apps runtime so they can be accessed with `process.env`.
     - uses: file/createOrUpdateEnvironmentFile
       with:
-          target: ./.env
+          target: ./.localConfigs
           envs:
               BOT_ID: ${{BOT_ID}}
               BOT_PASSWORD: ${{SECRET_BOT_PASSWORD}}