SlackAPI icon indicating copy to clipboard operation
SlackAPI copied to clipboard

Add more examples

Open glennblock opened this issue 8 years ago • 18 comments

Comprehensive docs would be nice, but minimally it would help if there were more examples, like showing how to actually post a message to a channel :-)

glennblock avatar Jun 21 '16 13:06 glennblock

I'd like to second this. I'm trying to write a prototype application using this library and am having to refer to other projects to get an idea of how this library is supposed to work. So far it's proving very difficult.

kenrachynski avatar Jul 06 '16 20:07 kenrachynski

3rd this - How do you receive messages? I can't see any events for incoming messages?

chinswain avatar Jul 12 '16 17:07 chinswain

The SlackSocketClient has an incoming messages event.

Zaicon avatar Jul 12 '16 21:07 Zaicon

Check issue no 3 (closed) - Unless I've missed something the event is not firing:

Dim gSlackClient = New SlackSocketClient("xxxxxx")
AddHandler gSlackClient.OnHello, AddressOf OnSlackHello
AddHandler gSlackClient.OnMessageReceived, AddressOf OnSlackMessageRecieved
gSlackClient.Connect(AddressOf OnSlackConnected)

Private Sub OnSlackHello()
     console.writeline("Hello") 'Fires
   End Sub

Private Sub OnSlackMessageRecieved(ByVal obj As NewMessage)
     Console.WriteLine(obj.text) 'Nothing
   End Sub

Private Sub OnSlackConnected(ByVal LoginResponse As LoginResponse)
     Console.WriteLine("connected") 'Fires
End Sub

chinswain avatar Jul 12 '16 21:07 chinswain

your app needs to stay running after you call .Connect(). the SlackAPI doesn't do that on its own.

kenrachynski avatar Jul 12 '16 21:07 kenrachynski

It's a winforms app so the connection is open.

chinswain avatar Jul 12 '16 22:07 chinswain

Are you running it on a separate thread from the UI thread? Maybe the thread is closing.

Fausto-Payano-Axomic avatar Jul 15 '16 17:07 Fausto-Payano-Axomic

Here is the C# I have running now in LINQPad if this helps.

var authToken = "ADD YOUR TOKEN HERE";
SlackSocketClient client = new SlackSocketClient(authToken);
SlackClient client2 = new SlackClient(authToken);
client2.TestAuth((art) => art.Dump());
client.Connect((connected) =>
{
        //This is called once the client has emitted the RTM start command
        "Started".Dump();
}, () =>
{
        //This is called once the RTM client has connected to the end point
        "Connected".Dump();
});

client.OnMessageReceived += (message) =>
{
    message.Dump();
    if (message.type == "message" && message.text == "test")
    {
        client.SendMessage((mr) => mr.Dump("Message Received"), message.channel, "Testing Socket");
        var buttons = new Attachment();
        buttons.text = "Lets pick a button";
        buttons.color = "#FF0000";
        client2.PostMessage((pmr) => pmr.Dump("Post Message Received"), message.channel, "Testing SlackClient", attachments: new[] { buttons});
    }
};

The easiest way to see how it works is to have a play with linqpad or check out the integration tests.

I have implemented both the websocket sending of a message and web api posting a message in this as well.

andymac4182 avatar Jul 25 '16 03:07 andymac4182

@chinswain I just used your exact code in LINQPad with my Auth token and it works.

andymac4182 avatar Jul 25 '16 03:07 andymac4182

Here's a simple gist I had use for scriptcs.

https://gist.github.com/glennblock/8bab71fb01ddd26e09127aba2d41d02a On Sun, Jul 24, 2016 at 8:50 PM Andrew McClenaghan [email protected] wrote:

@chinswain https://github.com/chinswain I just used your exact code in LINQPad with my Auth token and it works.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/Inumedia/SlackAPI/issues/52#issuecomment-234830579, or mute the thread https://github.com/notifications/unsubscribe-auth/AAInRDJ6cQhcy-mTXFVIQsXwBCkenn0Eks5qZDJ3gaJpZM4I6tyl .

glennblock avatar Jul 25 '16 04:07 glennblock

Can we send Messages with Buttons and Attachments using this SlackAPI?

vanshita-tilwani avatar Jun 13 '17 09:06 vanshita-tilwani

@Vanshita see the example from @andymac4182 earlier in this thread. It includes a button from my read. I haven't tried it out, though.

kenrachynski avatar Jun 13 '17 20:06 kenrachynski

Hey @kenrachynski. Thanks for helping me. I tried the same code, but in Visual Studio 2015 with some changes and It is working now. One more thing, I wish to send a direct message with all buttons and attachments instead of posting to a channel, I cannot find a function like PostMessage with post to direct user instead of channel. Could you please help me?

vanshita-tilwani avatar Jun 14 '17 08:06 vanshita-tilwani

@Vanshita from memory you can post to the username instead of the #channel and that will work.

andymac4182 avatar Jun 14 '17 21:06 andymac4182

@andymac4182 It is working when I am passing the user Id to the function, but not with username. Also, I am able to get the user list only from RTM and not websocket.

vanshita-tilwani avatar Jun 15 '17 05:06 vanshita-tilwani

I agree that this library is missing some good examples and documentation how to use it. Especially for beginners its currently pretty hard to figure out how it works.

I therefore added a simple but complete example for sending a message to the wiki. Feedback is of course welcome! https://github.com/Inumedia/SlackAPI/wiki/Complete-example-for-sending-a-message

ErikKalkoken avatar Nov 17 '18 16:11 ErikKalkoken

Hi I'm a beginner for this API and had a trouble with sending and receiving messages simultaneously with SlackSocketClient. I managed to find a solution and add it to the wiki: https://github.com/Inumedia/SlackAPI/wiki/RTM-API-example-for-just-parroting-messages-received But review is required, because I'm not confident of my solution and English writing skill honestly...

Detsudetsu avatar May 16 '20 06:05 Detsudetsu

I'd like to see examples for interacting with dialogs. I noticed a Dialog model in the library. But I don't know how to use it.

lorddev avatar Jun 07 '21 16:06 lorddev