//native
export type DynSelect_team_id = string
// Dropdown of the teams the connected user has joined.
export async function team_id(auth: RT.MsTeams) {
const response = await fetch(
`https://graph.microsoft.com/v1.0/me/joinedTeams`,
{
headers: {
Authorization: `Bearer ${auth.token}`,
Accept: "application/json",
},
}
)
if (!response.ok) {
throw new Error(`${response.status} ${await response.text()}`)
}
const { value } = (await response.json()) as { value: any[] }
return value.map((x) => ({ value: x.id, label: x.displayName }))
}
export type DynSelect_channel_id = string
// Dropdown of the chosen team's channels.
export async function channel_id(auth: RT.MsTeams, team_id: string) {
if (team_id == null || team_id === "") return []
const response = await fetch(
`https://graph.microsoft.com/v1.0/teams/${encodeURIComponent(team_id)}/channels`,
{
headers: {
Authorization: `Bearer ${auth.token}`,
Accept: "application/json",
},
}
)
if (!response.ok) {
throw new Error(`${response.status} ${await response.text()}`)
}
const { value } = (await response.json()) as { value: any[] }
return value.map((x) => ({ value: x.id, label: x.displayName }))
}
/**
* List Message Replies
* List the replies to a channel message. Pass the returned @odata.nextLink as `next_link` for the next page. Requires ChannelMessage.Read.All, which needs admin consent and is not a connection default: tick it when connecting.
*/
export async function main(
auth: RT.MsTeams,
team_id: DynSelect_team_id,
channel_id: DynSelect_channel_id,
message_id: string,
top: number = 20,
next_link: string | undefined
) {
if (
next_link != null &&
next_link !== "" &&
!next_link.startsWith("https://graph.microsoft.com/")
) {
throw new Error(
"next_link must be an @odata.nextLink returned by Microsoft Graph"
)
}
let url: URL
if (next_link != null && next_link !== "") {
url = new URL(next_link)
} else {
url = new URL(
`https://graph.microsoft.com/v1.0/teams/${encodeURIComponent(team_id)}/channels/${encodeURIComponent(channel_id)}/messages/${encodeURIComponent(message_id)}/replies`
)
url.searchParams.append("$top", String(top))
}
const response = await fetch(url, {
headers: {
Authorization: `Bearer ${auth.token}`,
Accept: "application/json",
},
})
if (!response.ok) {
throw new Error(`${response.status} ${await response.text()}`)
}
return await response.json()
}
Submitted by hugo989 2 hours ago