Skip to content

[Messages] Create

Julian Curtis-Zilius edited this page May 16, 2018 · 11 revisions

The create method allows you to send messages on behalf of the user. When called, the user will be presented with a popup window that includes details of the message you wish to send. For security, the user must click the "Send" button. Certain fields in the popup can be disabled if you don't want the user to be able to edit them. For example, some applications may choose to show the message box natively or on the Canvas page itself. In this scenario, you should disable all fields when you initiate the call because the user already had a chance to enter their message.

Overview of fields


  • recipient: The Canvas ID of the user that will receive the message.
  • subject: The subject of the message. It's not recommended to rely on this as it won't be included if that user has already received a message from the sender.
  • body: The body of the message.
  • details: We recommend using this field to explain to the user why you need to send a message. The user will be presented with this text as well as the URL of the website calling this method. However, these details will not be sent in the message.
  • disabledFields: An array of fields that the user will not be able to edit. For example, you might not want the user to be able to edit the recipient. In the code below, both the recipient and the subject fields have been disabled from editing by the user.

Canvas Code


Instead of using Javascript, you can now use Canvas Code. Simply add this HTML onto any content area in Canvas and it will be rendered with CanvasTools. The fields remain the same. Just use the example below. You can also use the CanvasTools Editor for a faster and simpler method.

<div class="hidden canvastools canvastools-message-send">
	<a class="Button canvastools-button">Send Message</a>
	<a class="canvastools-field canvastools-recipient">1234</a>
	<a class="canvastools-field canvastools-subject">Message subject.</a>
	<a class="canvastools-field canvastools-body">Message body.</a>
</div>

API Use


// The ID of the CanvasTools Chrome Extension (Don't change this)
var editorExtensionId = "gmdmngbeceipkojacdoljnllcnfpdgce";
var message = {
	send: {
		recipient: "1234",
		subject: "Message subject.",
		body: "Message body.",
		details: "We need to send this message to report a problem.",
		disabledFields: ['recipient', 'subject']
	}
}
chrome.runtime.sendMessage(editorExtensionId, {message: message}, function(response) {
    if (response.message.send)
        console.log('Message prompt created successfully!')
});

Executing the above code would result in a message popup that looks like this: