//native
/**
* Search Messages
* Search the chat and channel messages the connected user can see with a KQL query (e.g. `budget from:alice`), ranked by relevance. Requires Chat.Read (covered by the default Chat.ReadWrite); channel messages are only searched when ChannelMessage.Read.All is granted (admin consent, not a default).
*/
export async function main(
auth: RT.MsTeams,
query_string: string,
from: number = 0,
size: number = 25
) {
const payload = {
requests: [
{
entityTypes: ["chatMessage"],
query: { queryString: query_string },
from,
size,
},
],
}
const response = await fetch(
`https://graph.microsoft.com/v1.0/search/query`,
{
method: "POST",
headers: {
Authorization: `Bearer ${auth.token}`,
"Content-Type": "application/json",
Accept: "application/json",
},
body: JSON.stringify(payload),
}
)
if (!response.ok) {
throw new Error(`${response.status} ${await response.text()}`)
}
return await response.json()
}
Submitted by hugo989 2 hours ago