Skip to content

Commit 684a78b

Browse files
author
=
committed
minimal implementation of entities livestreaming
1 parent e680dd4 commit 684a78b

1 file changed

Lines changed: 27 additions & 66 deletions

File tree

packages/core/src/utils/getActivityLivestreamingMetadata.ts

Lines changed: 27 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import {
44
integer,
55
literal,
66
minValue,
7+
nonEmpty,
78
number,
89
object,
910
optional,
@@ -29,15 +30,20 @@ type StreamData = {
2930

3031
const streamDataSchema = object({
3132
streamId: optional(undefinedable(string())),
32-
streamSequence: streamSequenceSchema,
33+
streamSequence: optional(streamSequenceSchema),
3334
streamType: union([literal('streaming'), literal('informative'), literal('final')])
3435
});
3536

3637
const livestreamingActivitySchema = union([
3738
// Interim.
3839
object({
3940
attachments: optional(array(any()), EMPTY_ARRAY),
40-
channelData: any(),
41+
channelData: object({
42+
// "streamId" is optional for the very first activity in the session.
43+
streamId: optional(undefinedable(string())),
44+
streamSequence: streamSequenceSchema,
45+
streamType: literal('streaming')
46+
}),
4147
id: string(),
4248
// "text" is optional. If not set or empty, it presents a contentless activity.
4349
text: optional(undefinedable(string())),
@@ -47,7 +53,12 @@ const livestreamingActivitySchema = union([
4753
// Informative message.
4854
object({
4955
attachments: optional(array(any()), EMPTY_ARRAY),
50-
channelData: any(),
56+
channelData: object({
57+
// "streamId" is optional for the very first activity in the session.
58+
streamId: optional(undefinedable(string())),
59+
streamSequence: streamSequenceSchema,
60+
streamType: literal('informative')
61+
}),
5162
id: string(),
5263
// Informative may not have "text", but should have abstract instead (checked later)
5364
text: optional(undefinedable(string())),
@@ -57,7 +68,12 @@ const livestreamingActivitySchema = union([
5768
// Conclude with a message.
5869
object({
5970
attachments: optional(array(any()), EMPTY_ARRAY),
60-
channelData: any(),
71+
channelData: object({
72+
// "streamId" is required for the final activity in the session.
73+
// The final activity must not be the sole activity in the session.
74+
streamId: pipe(string(), nonEmpty()),
75+
streamType: literal('final')
76+
}),
6177
id: string(),
6278
// If "text" is empty, it represents "regretting" the livestream.
6379
text: optional(undefinedable(string())),
@@ -67,7 +83,12 @@ const livestreamingActivitySchema = union([
6783
// Conclude without a message.
6884
object({
6985
attachments: optional(array(any()), EMPTY_ARRAY),
70-
channelData: any(),
86+
channelData: object({
87+
// "streamId" is required for the final activity in the session.
88+
// The final activity must not be the sole activity in the session.
89+
streamId: pipe(string(), nonEmpty()),
90+
streamType: literal('final')
91+
}),
7192
id: string(),
7293
// If "text" is not set or empty, it represents "regretting" the livestream.
7394
text: optional(undefinedable(literal(''))),
@@ -76,66 +97,6 @@ const livestreamingActivitySchema = union([
7697
})
7798
]);
7899

79-
// const livestreamingActivitySchema = union([
80-
// // Interim.
81-
// object({
82-
// attachments: optional(array(any()), EMPTY_ARRAY),
83-
// channelData: object({
84-
// // "streamId" is optional for the very first activity in the session.
85-
// streamId: optional(undefinedable(string())),
86-
// streamSequence: streamSequenceSchema,
87-
// streamType: literal('streaming')
88-
// }),
89-
// id: string(),
90-
// // "text" is optional. If not set or empty, it presents a contentless activity.
91-
// text: optional(undefinedable(string())),
92-
// type: literal('typing')
93-
// }),
94-
// // Informative message.
95-
// object({
96-
// attachments: optional(array(any()), EMPTY_ARRAY),
97-
// channelData: object({
98-
// // "streamId" is optional for the very first activity in the session.
99-
// streamId: optional(undefinedable(string())),
100-
// streamSequence: streamSequenceSchema,
101-
// streamType: literal('informative')
102-
// }),
103-
// id: string(),
104-
// // Informative may not have "text", but should have abstract instead (checked later)
105-
// text: optional(undefinedable(string())),
106-
// type: literal('typing'),
107-
// entities: optional(array(any()), EMPTY_ARRAY)
108-
// }),
109-
// // Conclude with a message.
110-
// object({
111-
// attachments: optional(array(any()), EMPTY_ARRAY),
112-
// channelData: object({
113-
// // "streamId" is required for the final activity in the session.
114-
// // The final activity must not be the sole activity in the session.
115-
// streamId: pipe(string(), nonEmpty()),
116-
// streamType: literal('final')
117-
// }),
118-
// id: string(),
119-
// // If "text" is empty, it represents "regretting" the livestream.
120-
// text: optional(undefinedable(string())),
121-
// type: literal('message')
122-
// }),
123-
// // Conclude without a message.
124-
// object({
125-
// attachments: optional(array(any()), EMPTY_ARRAY),
126-
// channelData: object({
127-
// // "streamId" is required for the final activity in the session.
128-
// // The final activity must not be the sole activity in the session.
129-
// streamId: pipe(string(), nonEmpty()),
130-
// streamType: literal('final')
131-
// }),
132-
// id: string(),
133-
// // If "text" is not set or empty, it represents "regretting" the livestream.
134-
// text: optional(undefinedable(literal(''))),
135-
// type: literal('typing')
136-
// })
137-
// ]);
138-
139100
/**
140101
* Gets the livestreaming metadata of the activity, or `undefined` if the activity is not participating in a livestreaming session.
141102
*
@@ -191,7 +152,7 @@ export default function getActivityLivestreamingMetadata(activity: WebChatActivi
191152
type: !(
192153
output.text ||
193154
output.attachments?.length ||
194-
('entities' in output && getOrgSchemaMessage(output.entities)?.abstract)
155+
('entities' in output && getOrgSchemaMessage(output.entities))
195156
)
196157
? 'contentless'
197158
: streamData.streamType === 'informative'

0 commit comments

Comments
 (0)