Send automated notifications for new content using a custom function

This tutorial explains how to execute a custom function within a specific process. The function can send notifications and register data outside the timing of a standard function.

Below, we implement an automatic notification system for new content.

Creating the custom function

First, create the custom function.

1. Go to the function list screen

In the left sidebar menu, click [Operation] -> [Custom function].

Image from Gyazo

2. Go to the Custom function editor screen

Click the [Add] button at the upper right corner of the screen.

Image from Gyazo

Image from Gyazo

3. Enter a title and a Identifier

To create your custom function, first enter a title and a Identifier:

  • Title: Send e-mail when content is added in ID29
  • Identifier: sample1_trigger

The title and Identifier have to be unique (That is, two custom functions cannot have the same title and Identifier). For example, you can name the custom function after the endpoint used to implement it.

Image from Gyazo

4. Specify the components that use the custom function

Next, fill out the "Used by component(s)" field as follows:

  • Trigger: After adding content
  • Text field*:29

Image from Gyazo

*Fill in the text field with the ID of the topic group you want to implement the custom function for. You can find the topic group ID on the content structure list screen. In this example, 29 is the ID of the group created in the Creating topic group(s) tutorial. Adding new content to the group will trigger the execution of the custom function.

5. Write the code for the custom function

After specifying the components, write the code to send an automated e-mail to the editor. First, compose the subject and body of the e-mail. You can use the following variable:

variable nametypedescription
$topicsDataobjectContent data

Copy the following code into your editor:

{* Title *}
{assign var=mail_subject value=$topicsData.subject}
{* Body *}
{capture name=mail_body}
New content has been added.  

For details, please check below:
{$smarty.const.ROOT_MNG_URL}/management/topics/topics_edit/?topics_id={$topicsData.topics_id}
{/capture}
{assign var=mail_body value=$smarty.capture.mail_body}

fetched from Gyazo

Next, implement the e-mail delivery process. Copy the following code into your editor, replacing YOUR_MAIL_ADDRESS@example.com with your actual e-mail address:

{sendmail 
 to='YOUR_MAIL_ADDRESS@example.com'
 subject=$mail_subject
 contents=$mail_body}

fetched from Gyazo

6. Save the custom function

Now you have finished creating the custom function. Click [Add] to save these settings.

fetched from Gyazo

Verifying the notification delivery

To verify if the above custom function works, follow the steps below:

In the left sidebar menu, click [Content structure]. On the content structure list screen, click [Add] next to the group you created the custom function for.
Image from Gyazo

On the content editor screen, enter the topic contents and click [Add].
fetched from Gyazo

The system will send the notification e-mail to the address specified in the custom function.
fetched from Gyazo

Troubleshooting

If you did not receive the e-mail notification, refer to the FAQ below:

Note

Two custom functions cannot share the same caller. This tutorial configured the "Used by component(s)" field as follows:

  • Trigger: After adding content
  • Text field:29

Please ensure that you do not use these settings for other custom functions.

If you have any other questions, please use our contact form or Slack workspace.