How To Make A Fully Working Slack Bot In Under 10 Minutes
Slack is one of the leading communication platforms for millions of users. You can send instant messages, share documents, share images, and perform many different actions which improve the collaboration between team members. You can also automate and control many outside processes and even smart hardware with Bots in Slack.
The best thing of all is you can create Slack bots VERY EASILY using RAD Studio Delphi.
What is SDriver?
SDriver is a Delphi wrapper for Slack API by Andrea Magni who is one of our fabulous Embarcadero MVP team. SDriver is a free and open-source wrapper for Delphi developers.
The best thing is that the wrapper utilizes the native HTTP client libraries for each supported platform – System.Net.HttpClient. SDriver is also implemented with the System. Threading
library to work asynchronously.
What are the features of SDriver?
- Compatible with FireMonkey, Visual Component Library, and also Non-visual components
- Support for Message Attachments
- Support for Incoming Webhooks
- Implemented using Native HTTP Client Libraries
- Async implementation using Parallel Programming Library
What are Incoming Webhooks?
Incoming Webhooks are a simple way to post messages from apps into Slack. By creating Incoming Webhooks you get a unique URL which you can send a JSON payload with the message text and some options. Andrea’s source code repository contains links to explain this in more depth as does the official Slack website.
POST https://hooks.slack.com/services/T00000000/B00000000/XXXXXXXXXXXXXXXXXXXXXXXX Content–type: application/json { “text”: “Hello, world.” } |
{$R *.dfm}
uses
System.Diagnostics
, SDriver.Message, SDriver.Interfaces, SDriver.IncomingWebHook;
procedure TForm1.SendActionExecute(Sender: TObject);
var
LWebHook: IMessageBuffer;
LMessage: IMessage;
LStopWatch: TStopWatch;
begin
LStopWatch := TStopWatch.StartNew;
LMessage := TMessage.Create(EditMessage.Text + ‘ [‘ + TimeToStr(Now) + ‘]’);
LMessage.UserName := EditUserName.Text;
LMessage.Icon_URL := EditIcon_URL.Text;
LMessage.Icon_Emoji := EditIcon_Emoji.Text;
LMessage.Channel := EditChannel.Text;
LWebHook := TIncomingWebHook.Create(EditWebHookURL.Text, False);
LWebHook.Push(LMessage);
LWebHook.Flush;
end;
procedure TForm1.SendActionUpdate(Sender: TObject);
begin
SendAction.Enabled := (EditWebHookURL.Text ”) and (EditMessage.Text ”);
end;
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
implementation
{$R *.dfm}
uses System.Diagnostics , SDriver.Message, SDriver.Interfaces, SDriver.IncomingWebHook;
procedure TForm1.SendActionExecute(Sender: TObject); var LWebHook: IMessageBuffer; LMessage: IMessage;
LStopWatch: TStopWatch; begin LStopWatch := TStopWatch.StartNew;
LMessage := TMessage.Create(EditMessage.Text + ‘ [‘ + TimeToStr(Now) + ‘]’); LMessage.UserName := EditUserName.Text; LMessage.Icon_URL := EditIcon_URL.Text; LMessage.Icon_Emoji := EditIcon_Emoji.Text; LMessage.Channel := EditChannel.Text;
LWebHook := TIncomingWebHook.Create(EditWebHookURL.Text, False); LWebHook.Push(LMessage); LWebHook.Flush; end;
procedure TForm1.SendActionUpdate(Sender: TObject); begin SendAction.Enabled := (EditWebHookURL.Text > ”) and (EditMessage.Text > ”); end; |
Do you want to see how fast development with RAD Studio and Delphi can be – why not download a free trial now?