Skip to content

Commit fe55d65

Browse files
committed
simplify teams apis
1 parent cd104a6 commit fe55d65

File tree

3 files changed

+87
-2
lines changed

3 files changed

+87
-2
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
---
2+
title: Microsoft Teams
3+
description: Learn how to use the Microsoft Teams integration in your scripts.
4+
sidebar:
5+
order: 80
6+
---
7+
8+
GenAIScript provides APIs to post a message, with file attachments, to a given
9+
[Microsoft Teams](https://www.microsoft.com/en-us/microsoft-teams/) channel
10+
and it's SharePoint File share.
11+
12+
- using the CLI, posting the result of the AI generation
13+
14+
```sh "--teams-message"
15+
npx --yes genaiscript run ... --teams-message
16+
```
17+
18+
- using the API, posting a message with attachments
19+
20+
```js
21+
const channel = await host.teamsChannel()
22+
await channel.postMessage("Hello, World!")
23+
```
24+
25+
## Authentication
26+
27+
GenAIScript uses the Azure authentication client to interact with the Microsoft Graph.
28+
Login to your account using the Azure CLI.
29+
30+
```sh
31+
az login
32+
```
33+
34+
## Configuration
35+
36+
To use the Microsoft Teams integration with the [CLI](/genaiscript/reference/cli),
37+
you need to provide a link url to a Teams channel.
38+
39+
```txt .env
40+
GENAISCRIPT_TEAMS_CHANNEL_URL=https://teams.microsoft.com/l/...
41+
```
42+
43+
## API
44+
45+
The API works by create a client for the channel, then calling `postMessage`.
46+
47+
```js
48+
const channel = await host.teamsChannel()
49+
await channel.postMessage("Hello, World!")
50+
```
51+
52+
You can also attach files to the message.
53+
The files will be uploaded to the SharePoint Files folder.
54+
55+
```js
56+
await channel.postMessage("Hello, World!", {
57+
files: [{ filename: "file.txt" }],
58+
})
59+
```
60+
61+
Add a description to the file to populate this metdata.
62+
The description can be in markdown and will be rendered to Teams HTML as much as possible.
63+
64+
```js
65+
await channel.postMessage("Cool video!", {
66+
files: [
67+
{
68+
filename: "video.mp4",
69+
description: `Title
70+
description`,
71+
},
72+
],
73+
})
74+
```
75+
76+
For videos, GenAIScript will split the description into a subject/message
77+
to populate both entries in Microsoft Stream.

packages/core/src/teams.ts

+6
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,8 @@ async function microsoftTeamsChannelUploadFile(
118118
)
119119
}
120120
const j = (await res.json()) as MicrosoftTeamsEntity
121+
logVerbose(`teams: uploaded ${filename} to ${j.webUrl}`)
122+
121123
if (description) {
122124
const resg = await fetch(itemUrl, {
123125
method: "GET",
@@ -281,6 +283,10 @@ class MicrosoftTeamsChannelClient implements MessageChannelClient {
281283
export function createMicrosoftTeamsChannelClient(
282284
url: string
283285
): MessageChannelClient {
286+
if (!url)
287+
url =
288+
process.env.GENAISCRIPT_TEAMS_CHANNEL_URL ||
289+
process.env.GENAISCRIPT_TEAMS_URL
284290
if (!parseTeamsChannelUrl(url)) throw new Error("Invalid Teams channel URL")
285291
return new MicrosoftTeamsChannelClient(url)
286292
}

packages/core/src/types/prompt_template.d.ts

+4-2
Original file line numberDiff line numberDiff line change
@@ -4331,10 +4331,12 @@ interface PromptHost
43314331
python(options?: PythonRuntimeOptions): Promise<PythonRuntime>
43324332

43334333
/**
4334-
* Gets a client to a Microsoft Teams channel from a share link URL. Uses Azure CLI login.
4334+
* Gets a client to a Microsoft Teams channel from a share link URL;
4335+
* uses `GENAISCRIPT_TEAMS_CHANNEL_URL` environment variable if `shareUrl` is not provided.
4336+
* Uses Azure CLI login for authentication.
43354337
* @param url
43364338
*/
4337-
teamsChannel(shareUrl: string): Promise<MessageChannelClient>
4339+
teamsChannel(shareUrl?: string): Promise<MessageChannelClient>
43384340
}
43394341

43404342
interface WorkspaceFileWithDescription extends WorkspaceFile {

0 commit comments

Comments
 (0)