SendMessageWithOptions not available in Go SDK

Using the v2.5.0 of the Go SDK for Courier to add idempotent keys on the notifications but can’t seem to find the SendMessageWithOptions method on the client. Any ideas on what is going on?

they @sam I can confirm SendMessageWithOptions function exists on the client (courier-go/send.go at 6172d935aa3c5ec3894e51ab2313ff789755a506 · trycourier/courier-go · GitHub for ref) - can you check if you’re using the v2 client?

I have “github.com/trycourier/courier-go/v2” imported which I believe is the v2 client, but correct me if I’m wrong. I understand that the function exists, which is why I am confused. Here is the list of “send” methods I can find.


Any ideas on how to proceed?

update: realized that you guys haven’t released the feature yet in v2.5.0 so I manually got the v2.5.1 package. Still does not seem to work as I am getting The 'event' parameter is required HTTP status 400 errors. Any ideas or is the SDK just not ready to handle idempotency keys yet?

Thanks for bringing this to our attention! We have released a new version of the SDK to address this issue. Below please find a sample code snippet to get this running.

client := courier.CreateClient("<YOUR_AUTH_TOKEN>", nil)
	expiration := time.Now().Add(time.Hour * 24)
	message := map[string]interface{}{
		"message": map[string]interface{}{
			"to": map[string]string{
				"email": "foo@example.com",
			},
			"content": map[string]string{
				"title": "Welcome!",
				"body":  "Thanks for signing up Harry Potter",
			},
			"routing": map[string]interface{}{
				"method":   "single",
				"channels": []string{"email"},
			},
		},
	}
	requestID, err := client.SendMessageWithOptions(context.Background(),
		message,
		"POST",
		courier.WithIdempotencyKey("fake-key-6"),
		courier.WithIdempotencyKeyExpiration(expiration),
	)
	if err != nil {
		log.Fatalln(err)
	}
	log.Println(requestID)
1 Like

Note: Basically the second param has to be inside a “message” key. Make sure you try this with a new idempotency key otherwise it’ll reuse the older one you’ve tried with before and give back 400 because that old key would get tied to that 400 response.

Here’s a screenshot of repl.it we could verify this change in:

Let us know how it goes - happy to hop on a call if you’d like.

2 Likes

Thank you all for the help! I will give this a try!

1 Like

Thanks for the help guys! Just updated our backend with the new SDK and everything works now.

1 Like

Hey guys! One more update/question:

We are finding that everything works for sending to emails and public slack channels, but we get the same “The 'event' parameter is required” HTTP 400 status when sending to private slack channels. Here is a sample code of what we are doing. This first image is a code snippet of us sending to a public slack channel, which we have confirmed to be working.

This second image is a code snippet of us trying to send a private slack message, which seems to be failing. Any ideas on what could be happening?

note: this worked in the previous version of the SDK when we did not yet add idempotency keys.

Hey @sam,

Could it be that your Slack app doesn’t have the correct scopes added? Sending DMs through Slack require additional scopes like im:write. Using a Slack-associated email for DMs requires the additional scopes users:read and users:read.email added to your Slack app.

If you’d rather use the Slack user_id you’d only need to add the im:write scope to your Slack app.

Let me know!

Hi! As mentioned in the thread, I’ve used the plain SendMessage function in v2.5.0 of the SDK and tested it to work, so it just does not work with this SendMessageWithOptions function. As well, I have configured the slack app to include all the necessary scopes and have tested each with cURL much before exploring Courier.

Thank you!