UNPKG

1.44 kBJavaScriptView Raw
1"use strict";
2/**
3 * @module botbuilder
4 */
5/**
6 * Copyright (c) Microsoft Corporation. All rights reserved.
7 * Licensed under the MIT License.
8 */
9Object.defineProperty(exports, "__esModule", { value: true });
10exports.validateAndFixActivity = void 0;
11/**
12 * Validates an [Activity](xref:botbuilder-core.Activity) and formats the timestamp fields.
13 * @param activity [Activity](xref:botbuilder-core.Activity) to be validated.
14 * @returns The [Activity](xref:botframework-schema.Activity).
15 */
16function validateAndFixActivity(activity) {
17 if (typeof activity !== 'object') {
18 throw new Error(`validateAndFixActivity(): invalid request body.`);
19 }
20 if (typeof activity.type !== 'string') {
21 throw new Error(`validateAndFixActivity(): missing activity type.`);
22 }
23 if (typeof activity.timestamp === 'string') {
24 activity.rawTimestamp = activity.timestamp;
25 activity.timestamp = new Date(activity.timestamp);
26 }
27 if (typeof activity.expiration === 'string') {
28 activity.rawExpiration = activity.expiration;
29 activity.expiration = new Date(activity.expiration);
30 }
31 if (typeof activity.localTimestamp === 'string') {
32 activity.rawLocalTimestamp = activity.localTimestamp;
33 activity.localTimestamp = new Date(activity.localTimestamp);
34 }
35 return activity;
36}
37exports.validateAndFixActivity = validateAndFixActivity;
38//# sourceMappingURL=activityValidator.js.map
\No newline at end of file