Skip to content

Commit 92cc331

Browse files
authored
Merge pull request #67 from Jeffders/auth01
Adding OAuthCard, getSessionID and onPostActivity methods
2 parents af5afc7 + df84d00 commit 92cc331

2 files changed

Lines changed: 38 additions & 3 deletions

File tree

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "botframework-directlinejs",
3-
"version": "0.9.14",
3+
"version": "0.9.15",
44
"description": "client library for the Microsoft Bot Framework Direct Line 3.0 protocol",
55
"main": "built/directLine.js",
66
"types": "built/directLine.d.ts",

src/directLine.ts

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,15 @@ export interface Signin {
9898
}
9999
}
100100

101+
export interface OAuth {
102+
contentType: "application/vnd.microsoft.card.oauth",
103+
content: {
104+
text?: string,
105+
connectionname: string,
106+
buttons?: CardAction[]
107+
}
108+
}
109+
101110
export interface ReceiptItem {
102111
title?: string,
103112
subtitle?: string,
@@ -181,7 +190,7 @@ export interface AnimationCard {
181190
}
182191
}
183192

184-
export type KnownMedia = Media | HeroCard | Thumbnail | Signin | Receipt | AudioCard | VideoCard | AnimationCard | FlexCard | AdaptiveCard;
193+
export type KnownMedia = Media | HeroCard | Thumbnail | Signin | OAuth | Receipt | AudioCard | VideoCard | AnimationCard | FlexCard | AdaptiveCard;
185194
export type Attachment = KnownMedia | UnknownMedia;
186195

187196
export interface User {
@@ -277,7 +286,8 @@ export interface IBotConnection {
277286
activity$: Observable<Activity>,
278287
end(): void,
279288
referenceGrammarId?: string,
280-
postActivity(activity: Activity): Observable<string>
289+
postActivity(activity: Activity): Observable<string>,
290+
getSessionId? : () => Observable<string>
281291
}
282292

283293
export class DirectLine implements IBotConnection {
@@ -465,6 +475,31 @@ export class DirectLine implements IBotConnection {
465475
this.tokenRefreshSubscription.unsubscribe();
466476
this.connectionStatus$.next(ConnectionStatus.Ended);
467477
}
478+
479+
getSessionId(): Observable<string> {
480+
// If we're not connected to the bot, get connected
481+
// Will throw an error if we are not connected
482+
konsole.log("getSessionId");
483+
return this.checkConnection(true)
484+
.flatMap(_ =>
485+
Observable.ajax({
486+
method: "GET",
487+
url: `${this.domain}/session/getsessionid`,
488+
withCredentials: true,
489+
timeout,
490+
headers: {
491+
"Content-Type": "application/json",
492+
"Authorization": `Bearer ${this.token}`
493+
}
494+
})
495+
.map(ajaxResponse => {
496+
konsole.log("getSessionId response: " + ajaxResponse.response.sessionId);
497+
return ajaxResponse.response.sessionId as string;
498+
})
499+
.catch(error => this.catchPostError(error))
500+
)
501+
.catch(error => this.catchExpiredToken(error));
502+
}
468503

469504
postActivity(activity: Activity) {
470505
// Use postMessageWithAttachments for messages with attachments that are local files (e.g. an image to upload)

0 commit comments

Comments
 (0)