Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for HTML messages using teams chat message send #6483

Open
apc005 opened this issue Nov 9, 2024 · 9 comments
Open

Add support for HTML messages using teams chat message send #6483

apc005 opened this issue Nov 9, 2024 · 9 comments

Comments

@apc005
Copy link

apc005 commented Nov 9, 2024

Enhancement:

Let's add a --contentType [contentType] option that accepts text and html as values, but defaults to text.


Original issue

Priority

(Medium) I'm annoyed but I'll live

Description

Hi

When using second example on https://pnp.github.io/cli-microsoft365/cmd/teams/message/message-send I don't get a bold message but a text message with html tags:

1

Running the command with the debug option shows that the contentType is not set in the query:

2

The response shows it's handled as text:

3

It would be great to have an option to force the contentType value to "text" or "html"

Thanks

Steps to reproduce

m365 teams message send --teamId XXXXX --channelId YYYY --message "Hello World!"

Expected results

Hello World!

Actual results

Hello <b>World</b>!

Diagnostics

Lack of contentType in JSON data sent to O365

CLI for Microsoft 365 version

"v10.0.0"

nodejs version

v18.19.0

Operating system (environment)

Linux

Shell

bash

cli doctor

{
  "os": {
    "platform": "linux",
    "version": "#1 SMP PREEMPT Debian 1:6.6.51-1+rpt3 (2024-10-08)",
    "release": "6.6.51+rpt-rpi-2712"
  },
  "cliVersion": "10.0.0",
  "nodeVersion": "v18.19.0",
  "cliEntraAppId": "xxxx",
  "cliEntraAppTenant": "single",
  "authMode": "password",
  "cliEnvironment": "",
  "cliConfig": {
    "autoOpenLinksInBrowser": false,
    "copyDeviceCodeToClipboard": false,
    "output": "json",
    "printErrorsAsPlainText": false,
    "prompt": false,
    "showHelpOnFailure": false,
    "clientId": "xxxx",
    "helpMode": "options",
    "authType": "browser",
    "tenantId": "xxxx"
  },
  "roles": [],
  "scopes": {
    "https://graph.microsoft.com": [
      "AllSites.FullControl",
      "AppCatalog.ReadWrite.All",
      "AuditLog.Read.All",
      "Bookings.Read.All",
      "Calendars.Read",
      "ChannelMember.ReadWrite.All",
      "ChannelMessage.Read.All",
      "ChannelMessage.ReadWrite",
      "ChannelMessage.Send",
      "ChannelSettings.ReadWrite.All",
      "Chat.ReadWrite",
      "Community.ReadWrite.All",
      "Directory.AccessAsUser.All",
      "Directory.ReadWrite.All",
      "ExternalConnection.ReadWrite.All",
      "ExternalItem.ReadWrite.All",
      "Group.ReadWrite.All",
      "IdentityProvider.ReadWrite.All",
      "InformationProtectionPolicy.Read",
      "Mail.Read.Shared",
      "Mail.ReadWrite",
      "Mail.Send",
      "Notes.ReadWrite.All",
      "OnlineMeetingArtifact.Read.All",
      "OnlineMeetings.ReadWrite",
      "OnlineMeetingTranscript.Read.All",
      "PeopleSettings.ReadWrite.All",
      "Place.Read.All",
      "Policy.Read.All",
      "RecordsManagement.ReadWrite.All",
      "Reports.Read.All",
      "RoleAssignmentSchedule.ReadWrite.Directory",
      "RoleEligibilitySchedule.Read.Directory",
      "SecurityEvents.Read.All",
      "ServiceHealth.Read.All",
      "ServiceMessage.Read.All",
      "ServiceMessageViewpoint.Write",
      "Sites.Read.All",
      "Tasks.ReadWrite",
      "Team.Create",
      "TeamMember.ReadWrite.All",
      "TeamsAppInstallation.ReadWriteForUser",
      "TeamSettings.ReadWrite.All",
      "TeamsTab.ReadWrite.All",
      "TermStore.ReadWrite.All",
      "User.Invite.All",
      "User.ReadWrite.All",
      "profile",
      "openid",
      "email"
    ]
  }
}

Additional Info

No response

@apc005 apc005 added the bug label Nov 9, 2024
@milanholemans
Copy link
Contributor

Thank you for logging this issue @apc005.
@pnp/cli-for-microsoft-365-maintainers, do you agree that we should include an option --contentType [contentType] where people can provide the options text or html? I think in some cases it might be useful to still treat the input as plain text rather than HTML.

@apc005
Copy link
Author

apc005 commented Nov 9, 2024

"text" and "html" are the standard values defined by Microsoft - see https://learn.microsoft.com/fr-fr/graph/api/resources/itembody?view=graph-rest-beta

It seems "text" is the default value as this is how M$ graph handles the messages without contentType defined.

@milanholemans
Copy link
Contributor

@apc005 are you sure you are using teams message send? In the code, the content-type is specified:

data: {
body: {
contentType: 'html',
content: args.options.message
}
}

@apc005
Copy link
Author

apc005 commented Nov 9, 2024

My bad I'm using m365 teams chat message send

m365 teams chat message send --chatId  "$CHAT_ID"  -m "Text <b>Bold</b>" --debug
Executing command teams chat message send with options {"options":{"chatId":"19:[email protected]","message":"Text <b>Bold</b>","debug":true,"output":"json"}}
Executing command as 'xxxx', appId: xxx, tenantId: xxxx
Existing access token xxxx still valid. Returning...
Request:
{
  "url": "https://graph.microsoft.com/v1.0/chats/19:[email protected]/messages",
  "method": "post",
  "headers": {
    "Accept": "application/json;odata.metadata=none",
    "Content-Type": "application/json;odata=nometadata",
    "user-agent": "NONISV|SharePointPnP|CLIMicrosoft365/10.0.0",
    "accept-encoding": "gzip, deflate",
    "X-ClientService-ClientTag": "M365CLI:10.0.0",
    "authorization": "Bearer xxx"
  },
  "responseType": "json",
  "decompress": true,
  "data": {
    "body": {
      "content": "Text <b>Bold</b>"
    }
  }
}
Response:
{
  "url": "https://graph.microsoft.com/v1.0/chats/19:[email protected]/messages",
  "status": 201,
  "statusText": "Created",
  "headers": {
    "transfer-encoding": "chunked",
    "content-type": "application/json;odata.metadata=none;odata.streaming=true;IEEE754Compatible=false;charset=utf-8",
    "location": "https://teamsgraph.teams.microsoft.com/v1.0/chats('19:[email protected]')/messages('xxxxx')",
    "vary": "Accept-Encoding",
    "strict-transport-security": "max-age=31536000",
    "request-id": "xxxx",
    "client-request-id": "xxxx",
    "x-ms-ags-diagnostic": "{\"ServerInfo\":{\"DataCenter\":\"West Europe\",\"Slice\":\"E\",\"Ring\":\"5\",\"ScaleUnit\":\"008\",\"RoleInstance\":\"xxxx\"}}",
    "odata-version": "4.0",
    "date": "Sat, 09 Nov 2024 21:21:21 GMT",
    "connection": "close"
  },
  "data": {
    "id": "xxxx",
    "replyToId": null,
    "etag": "1731187281616",
    "messageType": "message",
    "createdDateTime": "2024-11-09T21:21:21.616Z",
    "lastModifiedDateTime": "2024-11-09T21:21:21.616Z",
    "lastEditedDateTime": null,
    "deletedDateTime": null,
    "subject": null,
    "summary": null,
    "chatId": "19:[email protected]",
    "importance": "normal",
    "locale": "en-us",
    "webUrl": null,
    "channelIdentity": null,
    "policyViolation": null,
    "eventDetail": null,
    "from": {
      "application": null,
      "device": null,
      "user": {
        "id": "xxxx",
        "displayName": "xxxx",
        "userIdentityType": "aadUser",
        "tenantId": "xxxx"
      }
    },
    "body": {
      "contentType": "text",
      "content": "Text <b>Bold</b>"
    },
    "attachments": [],
    "mentions": [],
    "reactions": []
  }
}
DONE

Timings:
api: 1645.839713ms
core: 22.843199ms
command: 1670.452409ms
options: 0.296354ms
total: 1697.740365ms
validation: 1.658365ms

@milanholemans
Copy link
Contributor

You are using teams chat message send, while the issue was about teams message send. The example you mentioned is also of teams message send.

@apc005
Copy link
Author

apc005 commented Nov 9, 2024

Yes, my bad. But chat messages do support html too…

@milanholemans
Copy link
Contributor

Yes, that's true, but that means it's an enhancement instead of a bug. We can add HTML support for sure.

@milanholemans milanholemans changed the title Bug report: Unable to Send HTML Messages in Teams Chat Add support for HTML messages using teams chat message send Nov 9, 2024
@apc005
Copy link
Author

apc005 commented Nov 9, 2024

Yes, that's true, but that means it's an enhancement instead of a bug. We can add HTML support for sure.

You’re absolutly right. Sorry for the mistake

@milanholemans
Copy link
Contributor

No problem at all 😊

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants