Question
I seek your advice. When sending a message to email from the TOTUM system, it is necessary to include a button (or a link) in the body of the email, which, when clicked, will perform a certain action in the system based on specific conditions. Is it possible to implement this task? Has anyone encountered this before?
Answer
Generate a link using row with keys key and value:
key — this is our secret key that we will verify.
value — the data for the action we will perform.
Convert this row into a string in json using the jsonCreate function.
To keep it secure, we encrypt it using the strEncrypt function.
To make it fit into get, we also need to encode it in a URL-safe format — strUrlEncode.
Next, I use an html template where I replace the get parameter with the resulting cipher in url-encode.
=: emailSend(to: "some-email.domen.com"; title: "crypt link"; body: str`"This is the link:" ++ $str`)
str: strReplace(str: $html; from: "{param}"; to: $url)
url: strUrlEncode(str: $param)
param: strEncrypt(str: $data)
data: jsonCreate(field: "key" = "my_secret_key"; field: "value" = "my_value")
```html:html
<a href="https://totum.online/Remotes/add_by_link?crypt={param}">some generated link</a>
```
We need to create remotes that will respond to an external request:
Create remotes, in my case named add_by_link.
Don't forget to assign the user from whom the remotes will be executed and enable it.
No need to url-decode because the server automatically decodes URL encoding when receiving a request, and we get the encrypted string in $#get[crypt].
Next, we need to decrypt what was passed in crypt and convert the json string into a row of totum using the jsonExtract function (it is fixed so it is not executed multiple times).
Now we compare the key, and if the check passes, we perform the action.
=: if(condition: $extract[key] = "my_secret_key"; then: $insert)
insert: insert(table: 'some_table'; field: 'field_with_value' = $extract[value]; inserts: "inserts"; log: true)
~extract: jsonExtract(text: $decrypt)
decrypt: strDecrypt(str: $#get[crypt])