Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const LOG_LENGTH = 20;
// Create server
const server = restify.createServer();
server.listen(process.env.PORT, () => {
console.log(`${ server.name } listening to ${ server.url }`);
});
server.use(restify.plugins.queryParser());
MicrosoftAppCredentials.trustServiceUrl('https://api.scratch.botframework.com');
MicrosoftAppCredentials.trustServiceUrl('https://state.scratch.botframework.com');
MicrosoftAppCredentials.trustServiceUrl('https://token.scratch.botframework.com');
MicrosoftAppCredentials.trustServiceUrl('https://api.ppe.botframework.com');
MicrosoftAppCredentials.trustServiceUrl('https://state.ppe.botframework.com');
MicrosoftAppCredentials.trustServiceUrl('https://token.ppe.botframework.com');
// Create adapter
const adapter = new BotFrameworkAdapter({
appId: process.env.MICROSOFT_APP_ID,
appPassword: process.env.MICROSOFT_APP_PASSWORD,
oAuthEndpoint: process.env.OAUTH_ENDPOINT,
openIdMetadata: process.env.OPENID_METADATA
});
// const storage = new MemoryStorage();
// const convoState = new ConversationState(storage);
// const userState = new UserState(storage);
// adapter.use(new BotStateSet(convoState, userState));
// Create server
const server = restify.createServer();
server.listen(process.env.PORT, () => {
console.log(`${ server.name } listening to ${ server.url }`);
});
server.use(restify.plugins.queryParser());
MicrosoftAppCredentials.trustServiceUrl('https://api.scratch.botframework.com');
MicrosoftAppCredentials.trustServiceUrl('https://state.scratch.botframework.com');
MicrosoftAppCredentials.trustServiceUrl('https://token.scratch.botframework.com');
MicrosoftAppCredentials.trustServiceUrl('https://api.ppe.botframework.com');
MicrosoftAppCredentials.trustServiceUrl('https://state.ppe.botframework.com');
MicrosoftAppCredentials.trustServiceUrl('https://token.ppe.botframework.com');
// Create adapter
const adapter = new BotFrameworkAdapter({
appId: process.env.MICROSOFT_APP_ID,
appPassword: process.env.MICROSOFT_APP_PASSWORD,
oAuthEndpoint: process.env.OAUTH_ENDPOINT,
openIdMetadata: process.env.OPENID_METADATA
});
// const storage = new MemoryStorage();
// const convoState = new ConversationState(storage);
// const userState = new UserState(storage);
// adapter.use(new BotStateSet(convoState, userState));
let numActivities = 0;
import generateDirectLineToken from './generateDirectLineToken';
import renewDirectLineToken from './renewDirectLineToken';
const LOG_LENGTH = 20;
// Create server
const server = restify.createServer();
server.listen(process.env.PORT, () => {
console.log(`${ server.name } listening to ${ server.url }`);
});
server.use(restify.plugins.queryParser());
MicrosoftAppCredentials.trustServiceUrl('https://api.scratch.botframework.com');
MicrosoftAppCredentials.trustServiceUrl('https://state.scratch.botframework.com');
MicrosoftAppCredentials.trustServiceUrl('https://token.scratch.botframework.com');
MicrosoftAppCredentials.trustServiceUrl('https://api.ppe.botframework.com');
MicrosoftAppCredentials.trustServiceUrl('https://state.ppe.botframework.com');
MicrosoftAppCredentials.trustServiceUrl('https://token.ppe.botframework.com');
// Create adapter
const adapter = new BotFrameworkAdapter({
appId: process.env.MICROSOFT_APP_ID,
appPassword: process.env.MICROSOFT_APP_PASSWORD,
oAuthEndpoint: process.env.OAUTH_ENDPOINT,
openIdMetadata: process.env.OPENID_METADATA
});
// const storage = new MemoryStorage();
import generateDirectLineToken from './generateDirectLineToken';
import renewDirectLineToken from './renewDirectLineToken';
const LOG_LENGTH = 20;
// Create server
const server = restify.createServer();
server.listen(process.env.PORT, () => {
console.log(`${ server.name } listening to ${ server.url }`);
});
server.use(restify.plugins.queryParser());
MicrosoftAppCredentials.trustServiceUrl('https://api.scratch.botframework.com');
MicrosoftAppCredentials.trustServiceUrl('https://state.scratch.botframework.com');
MicrosoftAppCredentials.trustServiceUrl('https://token.scratch.botframework.com');
MicrosoftAppCredentials.trustServiceUrl('https://api.ppe.botframework.com');
MicrosoftAppCredentials.trustServiceUrl('https://state.ppe.botframework.com');
MicrosoftAppCredentials.trustServiceUrl('https://token.ppe.botframework.com');
// Create adapter
const adapter = new BotFrameworkAdapter({
appId: process.env.MICROSOFT_APP_ID,
appPassword: process.env.MICROSOFT_APP_PASSWORD,
oAuthEndpoint: process.env.OAUTH_ENDPOINT,
openIdMetadata: process.env.OPENID_METADATA
});
// const storage = new MemoryStorage();
// const convoState = new ConversationState(storage);
import renewDirectLineToken from './renewDirectLineToken';
const LOG_LENGTH = 20;
// Create server
const server = restify.createServer();
server.listen(process.env.PORT, () => {
console.log(`${ server.name } listening to ${ server.url }`);
});
server.use(restify.plugins.queryParser());
MicrosoftAppCredentials.trustServiceUrl('https://api.scratch.botframework.com');
MicrosoftAppCredentials.trustServiceUrl('https://state.scratch.botframework.com');
MicrosoftAppCredentials.trustServiceUrl('https://token.scratch.botframework.com');
MicrosoftAppCredentials.trustServiceUrl('https://api.ppe.botframework.com');
MicrosoftAppCredentials.trustServiceUrl('https://state.ppe.botframework.com');
MicrosoftAppCredentials.trustServiceUrl('https://token.ppe.botframework.com');
// Create adapter
const adapter = new BotFrameworkAdapter({
appId: process.env.MICROSOFT_APP_ID,
appPassword: process.env.MICROSOFT_APP_PASSWORD,
oAuthEndpoint: process.env.OAUTH_ENDPOINT,
openIdMetadata: process.env.OPENID_METADATA
});
// const storage = new MemoryStorage();
// const convoState = new ConversationState(storage);
// const userState = new UserState(storage);
public async forwardToSkill(
turnContext: TurnContext,
activity: Partial,
tokenRequestHandler?: TokenRequestHandler|undefined
): Promise {
if (this.streamingTransportClient === undefined) {
// acquire AAD token
MicrosoftAppCredentials.trustServiceUrl(this.skillManifest.endpoint);
// put AAD token in the header
// MISSING Client doesn't has ctor with headers
// establish websocket connection
const url: string = ensureWebSocketUrl(this.skillManifest.endpoint);
const requestHandler: RequestHandler = new SkillCallingRequestHandler(
turnContext,
this.telemetryClient,
tokenRequestHandler,
this.handoffActivity
);
this.streamingTransportClient = new Client({url: url, requestHandler: requestHandler});
await this.streamingTransportClient.connectAsync();
}
public async forwardToSkill(
turnContext: TurnContext,
activity: Partial,
tokenRequestHandler?: TokenRequestHandler
): Promise {
// Serialize the activity and POST to the Skill endpoint
const requestOptions: RequestPrepareOptions = {
method: 'POST',
url: this.skillManifest.endpoint,
body: activity
};
const request: WebResource = new WebResource().prepare(requestOptions);
MicrosoftAppCredentials.trustServiceUrl(this.skillManifest.endpoint);
await this.appCredentials.signRequest(request);
const response: HttpOperationResponse = await this.httpClient.sendRequest(request);
if (response.status < 200 || response.status >= 300) {
const result: string = `HTTP error when forwarding activity to the skill: Status Code:${
response.status
}, Message: '${
response.bodyAsText
}'`;
await turnContext.sendActivity({
type: ActivityTypes.Trace,
text: result
});
private async authenticateConnection(req: WebRequest, channelService?: string): Promise {
if (!this.credentials.appId) {
// auth is disabled
return;
}
const authHeader: string = req.headers.authorization || req.headers.Authorization || '';
const channelIdHeader: string = req.headers.channelid || req.headers.ChannelId || req.headers.ChannelID || '';
// Validate the received Upgrade request from the channel.
const claims = await JwtTokenValidation.validateAuthHeader(authHeader, this.credentialsProvider, channelService, channelIdHeader);
// Add serviceUrl from claim to static cache to trigger token refreshes.
const serviceUrl = claims.getClaimValue(AuthenticationConstants.ServiceUrlClaim);
MicrosoftAppCredentials.trustServiceUrl(serviceUrl);
if (!claims.isAuthenticated) { throw new Error('Unauthorized Access. Request is not authorized'); }
}