External actions (notifications, push, email, API call)

What are external actions

Calling external actions is the ability to perform actions that go beyond the ability to work with the database via SQL. 

In some procedures, you can call external actions such as sending mail, SMS, clearing the cache, or creating a notification. This can be used in the following cases:

  1. In SaveItem when saving a form (SELECT 2)
  2. When the operation execute on a table (SELECT 2)
  3. In periodic sync (SELECT 2-10) calls)
  4. After changing the status of entities in the afterchangestatus (SELECT 2) procedure.
  5. In updating a field in the Table (SELECT 2)
  6. in executing the Request JS query (SELECT 3)

Example of this select2:

select 'email' type, -- email, sms, notification, clearcache
'ru@rudensoft.ru' [to], 'sub1' subject, 'bodyXXX'+@itemIDs body, ---EMAIL
'Text 1' msg, '723429234' [number], --- SMS
'' prefix, --CLEAR CACHE
'text1' text , 'ru@rudensoft.ru' [to], 'ticketExecutor' typeCode, 'http///' url, 'add111' additional -- notifications

Only the parameters that are relevant to the selected typewill be used.

If you need to do several external actions at once, you can register it via Union (and in this case specify all the parameters so that you can do union)

Description of parameters for an external action

Type-command types (notification, clearcache, email, emailtemplate, sms, apirequest)

Notifications on the site

select 'notification' type, 'text1' text , 'demo1' [to], 'ticketExecutor' typeCode, 'http///' url, 'add111' additional
  • text-notification text
  • to-whom notification
  • typeCode-notification type code (as_nt_notificationTypes)
  • url-extension to the notification
  • additional-additional information to the notification

See more about working with notifications

Clearing the cache

select 'clearcache' type, '' prefix

If a prefix is specified, the cache will only clean keys with the specified prefix (by default, it is as_).

Sending to telegram

-- easy sending
select 'telegram' type, 'username' [to], 'message text' [text]

-- sending with buttons
select 'telegram' type, 'text1' text, 'admin' [to], 'Btn1||test1' button1, " button2, 'Google||//https://google. com' button3, 1 isReplyButtons, '@falconSpaceTest' channel
  • to, channel-to whom we send it (if channel is set, we send it to the channel. to is the username in the system that a certain telegram is linked to). 
  • text message
  • button1, button2, button3-adding buttons to the message in the form "text|/data|/url". url - either an empty URL or a valid URL https://yandex.ru
  • isReplyButtons - if 1, the buttons will be displayed under the chat at the bottom (the Reply button type).

Sending a telegram message to the user (if they are subscribed to the system bot). 

Learn more about configuring the Telegram bot.

Email

select 'email' type, 'ru@rudensoft.ru' [to], 'sub1' subject, 'body1' body
  • to-who we send the message to
  • subject-message subject
  • body-email body
  • from (optional) - from whom the message is sent. If omitted, it is taken from the site Settings (the configuration code).from)
  • displayName(optional) - the sender's display name. If omitted, it is taken from the site Settings (mail.displayName configuration code)
  • server (optional) - sending server. If omitted, it is taken from the site Settings (mail.server configuration code)
  • loginEmail (optional)-login-mail. If omitted, it is taken from the site Settings (mail.loginEmail configuration code)
  • password (optional) - login password. If omitted, it is taken from the site Settings (mail.password configuration code)
  • port (optional) - port (25, 465). If omitted, it is taken from the site Settings (mail.port configuration code)
  • ssl (optional) - whether SSL is Required (true). If omitted, it is taken from the site Settings (mail.ssl configuration code)
  • bcc (optional) - Hidden copy. If omitted, it is taken from the site Settings (the configuration code).bcc)
  • cc (optional) - Copy. If omitted, it is taken from the site Settings (configuration code mail.cc).

See more about Email settings

Sending Email using the template

Email templates are created in the section /email-templates

 select 'emailtemplate' type, 'code1'code, 'ru@rudensoft.ru' [to], 'hecrus@mail.ru' bcc, 'Some parameter' name1, 'Name of some product' productName1
  • code is the notification template code
  • to, cc, bcc - who to send messages to (you can specify multiple addresses separated by commas).
  • The tag can be passed the optional from, displayName, server, loginEmail, password, port, and ssl (similar to type=email). 
  • Any parameters to replace in the message body and subject, such as name1. You can use pseudo-parameters like {name1} in the subject and body of the template message, which will be replaced with the corresponding parameter from the command. 

Note: for sending to work correctly, the system must have the tables as_mailing_templates, as_mailing_log

Sending SMS

select 'sms' type, 'Text 1' msg, '723429234' [number]
  • msg-SMS text
  • number-recipient's phone number

Calling an external API request

select 'apirequest' type, 'code1' code, 'name1' p1_name, 'val1' p1_value,..........'name10' p10_name, 'val10' p10_value
  • code-request code to the external API
  • p1_name, p1_value-parameters that are passed to the request (there can be up to 10 parameters , all parameters are optional).

See more about API requests

Generate Pictures

You can use the settings to generate an image file. In the file, you can write some text, place blocks, lines, and add images.All generation settings are specified via JSON in the options parameter (make sure to use quotation marks for names in JSON). 

Example: 

 select 'generateImage' type, '
    {
                "ImageModel":{
		"path":"/uploads/image.png",
		"width":"500",
		"height":"500",
		"backColor":"red",
                },
		"ImageText": [
			{
				"Text":"Some text",
				"x":"10",
				"y":"10",
				"width":"400",
				"height":"30",
				"color":"black",
				"backColor":"black",
				"fontSize":"18",
				"fontFamily":"Arial"

            },
			{
				"Text":"Second line",
				"x":"10",
				"y":"40",
				"width":"800",
				"height":"30",
				"color":"blue",
				"backColor":"black",
				"fontSize":"20",
				"fontFamily":"Arial"
			},
			{
				"Text":"третья линия",
				"x":"10",
				"y":"70",
				"width":"400",
				"height":"30",
				"color":"green",
				"backColor":"black",
				"fontSize":"18",
				"fontFamily":"Arial"
			}
		],
		"ImagePicture": [
			{
				"path":"/uploads/Дашборды.gif",
				"x":"0",
				"y":"100",
				"width":"100",
				"height":"75",
				"opacity":"0.9"
			},
			{
				"path":"/uploads/Дашборды.gif",
				"x":"0",
				"y":"175",
				"width":"150",
				"height":"75",
				"opacity":"0.9"
			}
		],
		"ImageLine": [
			{
				"x1":"0",
				"y1":"200",
				"x2":"300",
				"y2":"200",
				"thickness":"3",
				"color":"black"
			},
			{
				"x1":"150",
				"y1":"300",
				"x2":"50",
				"y2":"0",
				"thickness":"20",
				"color":"black"
			},
			{
				"x1":"10",
				"y1":"200",
				"x2":"150",
				"y2":"300",
				"thickness":"3",
				"color":"black"
			},
            {
				"x1":"0",
				"y1":"0",
				"x2":"150",
				"y2":"300",
				"thickness":"3",
				"color":"white"
			}
		]
    }
    ' options

Section ImageModel - sets general parameters: 

  • width height - the width and height of the image in pixels.
  • path-path to the save file
  • backColor-sets the shape color

ImageText is an array of text objects, each of Which has the following parameters: 

  • text - the text to write
  • x, y-coordinates of the block location
  • width, height - width and height of the block
  • color, backColor-text color and background color
  • fontSize, fontFamily - setting the font

ImagePicture is an array of Images that will be placed on the output image. They have the following parameters: 

  • x, y-coordinates of the block location
  • width, height - width and height of the block
  • path-path to the image
  • opacity-transparency (float from 0 to 1)

ImageLine is an array of Lines that will be placed on the output image. They have the following parameters: 

  • x1, y1, x2,y2-coordinates of the start and end points of the segment
  • thickness - line thickness
  • color - line color

Image processing (processimage)

You can transform images (change the size, quality, etc.)

To do this, follow these steps: 

 select 'processimage' type, '/uploads/viki.png' path, '/uploads/x-viki.png' url, 300 width, 300 height, 50 quality, '1' fitWithWhitespace, '' watermarkUrl
union
select 'processimage' type, '/uploads/viki2.png' path, '/uploads/x-viki2.png' url, 100 width, 100 height, 50 quality, '1' fitWithWhitespace, '' watermarkUrl

This way you can batch process multiple images. 

The parameters of the processimage

  • path-path to the source image.
  • url-path to the newly saved image.
  • width - width in pixels of the output image.
  • height - width in pixels of the output image.
  • quality - quality from 10 to 100. 
  • fitWithWhitespace - if 1, the image will be supplemented with spaces on the sides. If not 1-then transform by height and width.
  • watermarkUrl-path to the watermark image that is superimposed on the original image.

Important: the path and url must be different. 

Falcon Space is a functional web development platform on a narrow stack MS SQL/Bootstrap. Falcon Space Gettting started
Note