Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
store.subscribe(() => {
const state = store.getState();
if (state) {
const last = state[state.length - 1];
if (last && last.bot) {
const activity = last.bot;
const client = new ConnectorClient(credentials, activity.serviceUrl);
if (last.replyToId) {
// in this case we know this was a reply to an inbound activity
client.conversations.replyToActivity(activity.conversation.id, last.replyToId, activity)
.then(() => {
console.log('reply send with id: ' + last.replyToId);
});
}
else {
// otherwise just send the activity to teh conversation
client.conversations.sendToConversation(activity.conversation.id, activity)
.then(() => {
console.log('sent activity to conversation');
});
}
}
JwtTokenValidation.assertValidActivity(activity, req.headers.authorization, authenticator).then(() => {
// On message activity, reply with the same text
if (activity.type === ActivityTypes.Message) {
var reply = createReply(activity, `You said: ${activity.text}`);
const client = new ConnectorClient(credentials, activity.serviceUrl);
client.conversations.replyToActivity(activity.conversation.id, activity.id, reply)
.then((reply) => {
console.log('reply send with id: ' + reply.id);
});
}
res.send(202);
}).catch(err => {
console.log('Could not authenticate request:', err);
// Check if we have a streaming server. Otherwise, requesting a connector client
// for a non-existent streaming connection results in an error
if (!this.streamingServer) {
throw new Error(`Cannot create streaming connector client for serviceUrl ${serviceUrl} without a streaming connection. Call 'useWebSocket' or 'useNamedPipe' to start a streaming connection.`)
}
return new ConnectorClient(
credentials,
{
baseUri: serviceUrl,
userAgent: USER_AGENT,
httpClient: new StreamingHttpClient(this.streamingServer)
});
}
return new ConnectorClient(credentials, { baseUri: serviceUrl, userAgent: USER_AGENT });
}
public createConnectorClient(serviceUrl: string): ConnectorClient {
return new ConnectorClient(
this.credentials,
{
baseUri: serviceUrl,
userAgent: super['USER_AGENT'],
httpClient: new StreamingHttpClient(this.server)
});
}
private async verifyEmulatorConversation(id: string): Promise {
const client = new ConnectorClient(new EmulatorServiceCredentials() as any, {baseUri: process.env.EMULATOR_URL});
try {
const result = await client.conversations.getConversations();
return !!result.conversations.find(conversation => conversation.id === id);
} catch(e) {
return false;
}
}
}
createConnectorClient(serviceUrl) {
const client = new botframework_connector_1.ConnectorClient(this.credentials, serviceUrl);
client.addUserAgentInfo(USER_AGENT);
return client;
}
/**
function createClient(serviceUrl) {
if (serviceUrl) {
if (!clientCache.hasOwnProperty(serviceUrl)) {
clientCache[serviceUrl] = new botframework_connector_1.ConnectorClient(credentials, serviceUrl);
}
return clientCache[serviceUrl];
}
}
const responses = [];
private static async connectToEmulator(context: TurnContext): Promise {
const client = new ConnectorClient(new EmulatorServiceCredentials() as any, {baseUri: process.env.EMULATOR_URL});
const payload: ConversationParameters = {
bot: context.activity.recipient,
isGroup: context.activity.conversation.isGroup,
members: [context.activity.recipient],
activity: BotDebugger.trace(context.activity.conversation, 'https://www.botframework.com/schemas/debug', 'Debug', 'Debug Connection Request') as Activity,
channelData: null
};
try {
const result = await client.conversations.createConversation(payload);
if (result._response.status === 200) {
return result.id;
}
} catch (e) {
throw e;
}
}
public createConnectorClient(serviceUrl: string): ConnectorClient {
const client: ConnectorClient = new ConnectorClient(this.credentials, { baseUri: serviceUrl, userAgent: USER_AGENT });
return client;
}