Usually advising functions can be used to change the behavior of a function. But for this interactive function it would get complicated when looking at the source.
Fortunately org-mode
(version 9.1+) has a built-in method to add custom link types which is the preferred way in this case:
(org-link-set-parameters TYPE &rest PARAMETERS)
An example that should come close to what you have in mind:
(defun my-org-link-insert-slack-data (&optional arg)
"Get the slack link and insert the data."
(let ((slack-link (read-string "slack link: ")))
;; Use your function here to insert the slack data.
(insert slack-link)))
(org-link-set-parameters "slack" :complete #'my-org-link-insert-slack-data)
Evaluate the example code and then run M-x org-insert-link. The custom link type slack
can be selected:
Then it prompts you for the slack link and inserts the text entered at point.
Usually the completing function has to return a string. But as long as I have understood your question correctly you don't really want to insert a link. Therefore the function just inserts the text itself. Org will show an user error in the minibuffer (wrong type argument: stringp, nil
) but it still works.
It would probably be better to just use a function for this and not rely on org-insert-link
at all.