I am working with ms graph and i need to integrate with ms teams. In one case i have to send a message to a channel which will contain a channel mention (@). Currently i have found how to tag a specific user using java but i cant figure out how to mention the whole channel. It is posible to do so in ms graph and if yes how?
To be more specific here is an example. Assume that i have a team named TestTeam and this team has a channel named testChannel. i need to send a message where will contain @testChannel and will send a notification to everyone in this channel.
Also in slack api i am able to do this action by using "<!channel>" in my message.
This is the code i am using in order to tag a user:
static void send_message(String text, String mentionName, String channelName, String teamName, String accessToken) {
ensureGraphClient(accessToken);
Team team = getTeam(accessToken, teamName);
Channel channel = getChannel(accessToken, channelName, team);
User user = getUser(accessToken, mentionName);
if (userInChannel(user, team, channel)) {
ChatMessage chatMessage = new ChatMessage();
ItemBody body = new ItemBody();
body.contentType = BodyType.HTML;
body.content = String.format("%s. <at id=\"1\">%s</at> ", text, mentionName);
chatMessage.body = body;
ChatMessageMention m = new ChatMessageMention();
m.id = 1;
IdentitySet st = new IdentitySet();
Identity ide = new Identity();
ide.id = user.id;
ide.displayName = user.displayName;
st.user = ide;
m.mentioned = st;
m.mentionText = mentionName;
List<ChatMessageMention> cmmt = new LinkedList<>();
cmmt.add(m);
chatMessage.mentions = cmmt;
graphClient.teams(team.id).channels(channel.id).messages()
.buildRequest()
.post(chatMessage);
}
}
I also tried something similar in order to tag channels but it did not worked:
body.contentType = BodyType.HTML;
body.content = String.format("%s. <at id=\"1\">%s</at> ", text, "myChannel");
chatMessage.body = body;
ChatMessageMention m = new ChatMessageMention();
m.id = 1;
IdentitySet st = new IdentitySet();
Identity ide = new Identity();
ide.id = "19%xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx%40thread.tacv2";
ide.displayName = "myChannel";
st.user = ide;
m.mentioned = st;
m.mentionText = "myChannel";
List<ChatMessageMention> cmmt = new LinkedList<>();
cmmt.add(m);
chatMessage.mentions = cmmt;
graphClient.teams(team.id).channels(channel.id).messages()
.buildRequest()
.post(chatMessage);