|
| 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. |
0 commit comments