How to use the botframework-schema.ActivityTypes.Message function in botframework-schema

To help you get started, we’ve selected a few botframework-schema examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github microsoft / botbuilder-js / samples / echobot-connector-es6 / app.js View on Github external
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);
github microsoft / botbuilder-tools / packages / Chatdown / src / lib / index.ts View on Github external
continue;
    }

    // Indicates a new activity -
    // As more activity types are supported, this should
    // become a util or helper class.
    if (type) {
      let text = aggregate.substr(0, result.index).trim();
      if (text.length > 0) {
        currentActivity.text = text;
        currentActivity.timestamp = getIncrementedDate(delay);
        newActivities.push(currentActivity);
        // reset
        delay = messageTimeGap;
        currentActivity = createActivity({
          type: ActivityTypes.Message,
          from: parserModel.from,
          recipient: parserModel.recipient,
          conversationId: parserModel.conversation.id
        });
        currentActivity.text = '';
      }
      aggregate = aggregate.substr(result.index);
      if (type === ActivityTypes.Typing) {
        let newActivity = createActivity({
          type,
          recipient: parserModel.recipient,
          from: parserModel.from,
          conversationId: parserModel.conversation.id
        });
        newActivity.timestamp = getIncrementedDate(100);
        newActivities.push(newActivity);
github microsoft / botframework-solutions / templates / Enterprise-Template / src / typescript / enterprise-bot / src / dialogs / templateManager / templateManager.ts View on Github external
public async renderTemplate(turnContext: TurnContext, templateId: string, language?: string, data?: any): Promise {
        const fallbackLocales = this._languageFallback;

        if (language) {
            fallbackLocales.push(language);
        }

        fallbackLocales.push('default');

        // try each locale until successful
        for (const locale of fallbackLocales) {
            for (const renderer of this._templateRenderers) {
                const templateOutput = await renderer.renderTemplate(turnContext, locale, templateId, data);
                if (templateOutput) {
                    if (typeof templateOutput === 'string' || templateOutput instanceof String) {
                        return { type: ActivityTypes.Message, text: templateOutput as string } as Activity;
                    } else {
                        return templateOutput as Activity;
                    }
                }
            }
        }

        return undefined;
    }
}
github microsoft / botbuilder-js / libraries / botbuilder-core / src / showTypingMiddleware.ts View on Github external
// Pass in period as the delay to repeat at an interval.
                        startInterval(context, period, period);
                    } else {
                        // Do nothing! This turn is done and we don't want to continue sending typing indicators.
                    }
                },
                delay
            );
        }

        function stopInterval(): void {
            finished = true;
            if (hTimeout) { clearTimeout(hTimeout); }
        }

        if (context.activity.type === ActivityTypes.Message) {
            // Set a property to track whether or not the turn is finished.
            // When it flips to true, we won't send anymore typing indicators.
            finished = false;
            startInterval(context, this.delay, this.period);
        }

        // Let the rest of the process run.
        // After everything has run, stop the indicator!
        return await next().then(stopInterval, stopInterval);

    }
    private async sendTypingActivity(context: TurnContext): Promise {
github microsoft / BotFramework-Emulator / packages / app / client / src / state / sagas / chatSagas.spec.ts View on Github external
it('should handle the "copy message" selection', async () => {
      const commandServiceSpy = jest.spyOn(commandService, 'remoteCall').mockResolvedValue({ id: 'copy' });
      const clipboardSpy = jest.spyOn(Electron.clipboard, 'writeText');
      const activity = {
        valueType: ValueTypes.Activity,
        type: ActivityTypes.Trace,
        value: { type: ActivityTypes.Message, text: 'Hello Bot!' },
      };
      mockStore.dispatch(showContextMenuForActivity(activity));
      await Promise.resolve(true);
      expect(commandServiceSpy).toHaveBeenCalled();
      expect(clipboardSpy).toHaveBeenCalledWith('Hello Bot!');
    });
github microsoft / BotFramework-Emulator / packages / app / main / src / server / state / loggerAdapter.spec.ts View on Github external
it('should log a nested message in a trace activity', () => {
    const conversationId = 'convo1';
    const activity = {
      id: 'someId',
      label: 'Message sent',
      type: ActivityTypes.Trace,
      value: {
        type: ActivityTypes.Message,
        from: { role: 'bot' },
        text: 'Hello',
      },
    } as Activity;

    const logItems: LogItem[] = [
      textItem(LogLevel.Debug, '<- '),
      inspectableObjectItem(activity.type, activity),
      summaryTextItem(activity),
      textItem(LogLevel.Debug, '-> '),
      inspectableObjectItem(activity.value.type, activity.value),
      summaryTextItem(activity.value),
    ];

    loggerAdapter.logActivity(conversationId, activity, 'user');
    expect(mockLogToChat).toHaveBeenCalledWith(conversationId, ...logItems);
github microsoft / BotFramework-Emulator / packages / app / client / src / state / sagas / chatSagas.spec.ts View on Github external
it('should handle the "copy json" selection', async () => {
      const commandServiceSpy = jest.spyOn(commandService, 'remoteCall').mockResolvedValue({ id: 'json' });
      const clipboardSpy = jest.spyOn(Electron.clipboard, 'writeText');
      const activity = {
        valueType: '',
        type: ActivityTypes.Trace,
        value: { type: ActivityTypes.Message, text: 'Hello Bot!' },
      };
      await mockStore.dispatch(showContextMenuForActivity(activity));
      await Promise.resolve(true);
      expect(commandServiceSpy).toHaveBeenCalled();
      expect(clipboardSpy).toHaveBeenCalledWith(JSON.stringify(activity, null, 2));
    });
github microsoft / botbuilder-js / libraries / botbuilder-lg / src / activityFactory.ts View on Github external
private static buildActivity(messageValue: any): Partial {
        let activity: Partial = { type: ActivityTypes.Message };
        for (const key of Object.keys(messageValue)) {
            const property: string = key.trim();
            if (property === Evaluator.LGType) {
                continue;
            }

            const value: any = messageValue[key];

            switch (property.toLowerCase()) {
                case 'attachments':
                    activity.attachments = this.getAttachments(value);
                    break;
                case 'suggestedactions':
                    activity.suggestedActions = this.getSuggestions(value);
                    break;
                default:
github microsoft / botbuilder-tools / packages / Chatdown / lib / index.js View on Github external
function createActivity({ type = ActivityTypes.Message, recipient, from, conversationId }) {
    const activity = new Activity({ from, recipient, type, id: '' + activityId++ });
    activity.conversation = new ConversationAccount({ id: conversationId });
    return activity;
}
github microsoft / botframework-solutions / sdk / typescript / libraries / botbuilder-solutions / src / middleware / contentModeratorMiddleware.ts View on Github external
public async onTurn(context: TurnContext, next: () => Promise): Promise {
        if (context === undefined) {
            throw new Error('Context not found.');
        }

        if (context.activity.type === ActivityTypes.Message) {
            const textStream: Readable = this.textToReadable(context.activity.text);

            const credentials: CognitiveServicesCredentials = new CognitiveServicesCredentials(this.subscriptionKey);
            const client: ContentModeratorClient = new ContentModeratorClient(credentials, `${this.region}.api.cognitive.microsoft.com`);

            const screenResult: Object = await client.textModeration.screenText(
                'text/plain',
                textStream,
                {
                    language: 'eng',
                    autocorrect: true,
                    pII: true,
                    listId: undefined,
                    classify: true
                }
            );