7

Just playing with my first slack command. Is there any way of adding custom data from an external API for autocomplete. So what works perfectly right now, is calling the command /assign plus a slack user (both will be autocompleted, nice!). What I want/need is a list of items I would fetch from a remote endpoint, which can be selected by autocomplete.

Is this possible at all?

/assign @userX to [data_by_autocomplete]

Or do I need to solve that by a full conversation like:

=> /assign user @userX
=> BOT: Which task? Here is a list: ...
=> /assign taskY
=> BOT: Assigned TaskY to @userX

But this feels very cumbersome (and wrong). So basically what I want is a remotely fetched list for autocomplete in the same command.

PS: Command and functionality is a simplified example to illustrate the point.

everyman
  • 3,377
  • 1
  • 34
  • 33

1 Answers1

8

No, you can not use custom autocomplete within the command line, but you can use custom autocomplete with the the new interactive message menus.

So I would suggest to break it up into two steps.

  1. Enter slash command and provide username
  2. Show interactive menu with autocomplete
Erik Kalkoken
  • 30,467
  • 8
  • 79
  • 114
  • Where do you see anything about autocomplete? – CodyBugstein Aug 22 '18 at 16:26
  • All interactive menus including when using custom data as input, will automatically reduce the result list based on user input when typing. That is what I meant by auto-complete. – Erik Kalkoken Aug 22 '18 at 16:42
  • Are you sure? Where will it get the autocomplete suggestions from? – CodyBugstein Aug 22 '18 at 18:39
  • Yes. If you have a list with custom data you need a service to generate the suggestions. It receives the partial string of the user input and returns the list of matching items. If you use the built-in menus (e.g. user list), they are generated automatically by the Slack UI. Here is an example image: https://i.imgur.com/Zi0vKeM.png – Erik Kalkoken Aug 22 '18 at 21:52
  • That's great. I can't find any examples thoigh of how to implement this. I'd be interested in tying a field to Google Maps – CodyBugstein Aug 22 '18 at 21:58
  • Here is the link to the documentation on how dynamic menus work for starters: https://api.slack.com/docs/message-menus#menu_dynamic – Erik Kalkoken Aug 23 '18 at 09:43
  • It seems that these will autocomplete based on a list of pre-provided values, but cannot dynamically fetch suggestions from a third party source – CodyBugstein Aug 23 '18 at 16:57
  • No, that is not correct. The dynamic menu works with any custom data. As you can see in my example above I use it with a list of game items. Those are coming from a 3rd party API. Keep in mind though, that you properly need to build an adapter service between Slack and your 3rd party source. – Erik Kalkoken Aug 23 '18 at 17:33
  • Yes I see it now. Brilliant. Thank you. – CodyBugstein Aug 23 '18 at 17:44