Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions samples/nodejs/quickstart/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,12 +63,12 @@ npm test

Refresh the browser to start a new conversation with the Echo bot.

You should see a message from the bot like: `Echo running on Agents SDK version: {version}`
You should see a message from the agent: `Hello and Welcome!`


### Interact with the agent with WebChat UI using Azure Bot Service

1. [Create an Azure Bot](https://aka.ms/AgentsSDK-CreateBot)
1. [Create an Azure Bot](https://learn.microsoft.com/en-us/microsoft-365/agents-sdk/azure-bot-create-single-secret)
- Record the Application ID, the Tenant ID, and the Client Secret for use below

1. Configuring the token connection in the Agent settings
Expand Down
15 changes: 14 additions & 1 deletion samples/nodejs/quickstart/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion samples/nodejs/quickstart/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"test": "npm-run-all -p -r start:anon test-tool"
},
"dependencies": {
"@microsoft/agents-hosting": "^1.0.0",
"@microsoft/agents-hosting-express": "^1.0.0",
"express": "^5.1.0"
},
"devDependencies": {
Expand Down
74 changes: 0 additions & 74 deletions samples/nodejs/quickstart/src/agent.ts

This file was deleted.

53 changes: 34 additions & 19 deletions samples/nodejs/quickstart/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,25 +1,40 @@
import { AuthConfiguration, authorizeJWT, CloudAdapter, loadAuthConfigFromEnv, Request } from '@microsoft/agents-hosting'
import express, { Response } from 'express'
import { agentApp } from './agent'
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
import { startServer } from '@microsoft/agents-hosting-express'
import { TurnState, MemoryStorage, TurnContext, AgentApplication }
from '@microsoft/agents-hosting'
import { ActivityTypes } from '@microsoft/agents-activity'

const authConfig: AuthConfiguration = loadAuthConfigFromEnv()
const adapter = new CloudAdapter(authConfig)
// Create custom conversation state properties. This is
// used to store customer properties in conversation state.
interface ConversationState {
count: number;
}
type ApplicationTurnState = TurnState<ConversationState>

const server = express()
server.use(express.json())
server.use(authorizeJWT(authConfig))
// Register IStorage. For development, MemoryStorage is suitable.
// For production Agents, persisted storage should be used so
// that state survives Agent restarts, and operates correctly
// in a cluster of Agent instances.
const storage = new MemoryStorage()

server.post('/api/messages', async (req: Request, res: Response) => {
await adapter.process(req, res, async (context) => {
const app = agentApp
await app.run(context)
})
const agentApp = new AgentApplication<ApplicationTurnState>({
storage
})

const port = process.env.PORT || 3978
server.listen(port, () => {
console.log(`\nServer listening to port ${port} for appId ${authConfig.clientId} debug ${process.env.DEBUG}`)
}).on('error', (err) => {
console.error(err)
process.exit(1)
// Display a welcome message when members are added
agentApp.onConversationUpdate('membersAdded', async (context: TurnContext, state: ApplicationTurnState) => {
await context.sendActivity('Hello and Welcome!')
})

// Listen for ANY message to be received. MUST BE AFTER ANY OTHER MESSAGE HANDLERS
agentApp.onActivity(ActivityTypes.Message, async (context: TurnContext, state: ApplicationTurnState) => {
// Increment count state
let count = state.conversation.count ?? 0
state.conversation.count = ++count

// Echo back users message
await context.sendActivity(`[${count}] You said: ${context.activity.text}`)
})

startServer(agentApp)