Formatting | laravel-slack-alerts-go | Spatie       

 SPATIE  

laravel-slack-alerts-go
=======================

spatie.be/open-source

  [Docs](https://spatie.be/docs)  [Laravel-slack-alerts-go](https://spatie.be/docs/laravel-slack-alerts-go/v1)  Formatting

 Version   v1      

 Other versions for crawler [v1](https://spatie.be/docs/laravel-slack-alerts-go/v1) 

  Formatting    
- [ Introduction ](https://spatie.be/docs/laravel-slack-alerts-go/v1/introduction)
- [ Installation ](https://spatie.be/docs/laravel-slack-alerts-go/v1/installation-and-setup)
- [ Usage ](https://spatie.be/docs/laravel-slack-alerts-go/v1/usage)
- [ Sending blocks ](https://spatie.be/docs/laravel-slack-alerts-go/v1/sending-blocks)
- [ Using multiple webhooks ](https://spatie.be/docs/laravel-slack-alerts-go/v1/using-multiple-webhooks)
- [ Queuing ](https://spatie.be/docs/laravel-slack-alerts-go/v1/queuing)
- [ Formatting ](https://spatie.be/docs/laravel-slack-alerts-go/v1/formatting)
- [ Testing ](https://spatie.be/docs/laravel-slack-alerts-go/v1/testing)
- [ Releasing ](https://spatie.be/docs/laravel-slack-alerts-go/v1/releasing)
- [ Changelog ](https://spatie.be/docs/laravel-slack-alerts-go/v1/changelog)
- [ Support us ](https://spatie.be/docs/laravel-slack-alerts-go/v1/support-us)

 Formatting
==========

### Markdown

You can format your messages with [Slack's markup](https://slack.com/help/articles/202288908-Format-your-messages).

```
err := slackalerts.Message(ctx, "A message *with some bold statements* and _some italicized text_.")
err = slackalerts.Message(ctx, "<https://spatie.be|This is a link to our homepage>")
```

### Emoji's

You can use the same emoji codes as in Slack, including custom emoji.

```
err := slackalerts.Message(ctx, ":smile: :custom-code:")
```

### Mentioning

You can use [mentions](https://api.slack.com/reference/surfaces/formatting#mentioning-users) to notify users and groups.

```
err := slackalerts.Message(ctx, "A message that notifies <@USER_ID> and everyone else who is <!here>")
```

### Icon Change

```
err := slackalerts.From(ctx).WithIconURL("https://example.com/tiny-icon.jpg").Message(ctx, "Some message.")
err = slackalerts.From(ctx).WithIconEmoji(":smile:").Message(ctx, "Some message.")
```

Modern Slack app webhooks ignore icon overrides. These options only affect legacy webhooks.

### Display Name Change

```
err := slackalerts.From(ctx).WithUsername("More Descriptive Name").Message(ctx, "Some message.")
```

Modern Slack app webhooks ignore username overrides and use the Slack app's configured name.

### Synchronous Dispatch

Use `Sync(true)` to send immediately before continuing execution. `Sync(false)` restores normal queued dispatch.

```
err := slackalerts.From(ctx).Sync(true).Message(ctx, "Some message.")
```

### Usage in tests

Use Laravel's HTTP fake to check actual payloads without sending messages to Slack. Use its queue fake when you only need to inspect dispatched jobs.

```
client := laraveltest.New(t, laravel.Options{
    Packages: []laravel.Package{slackalerts.New()},
}, laraveltest.Env(map[string]string{"SLACK_ALERT_WEBHOOK": "https://hooks.slack.test/alerts"}))
slack := httpclienttest.New(client).
    Respond("https://hooks.slack.test/*", httpclienttest.Text("ok")).
    PreventStrayRequests()

if err := slackalerts.Message(client.Context(), "New subscriber"); err != nil {
    t.Fatal(err)
}
slack.AssertSent(func(req *httpclienttest.Request) bool {
    return req.Data()["text"] == "New subscriber"
})
slack.AssertSentCount(1)
```

Import `go.laravel.com/laraveltest` and `go.laravel.com/httpclienttest` along with the package and Laravel. Laravel test applications execute jobs synchronously unless you install `queuetest.New(client)`.

Missing webhook names, empty URLs and disabled alerts are no-ops. Configured nonempty invalid URLs return errors without exposing the webhook secret. Builders return copies, so channel and identity overrides do not leak into later sends. Empty text and `"0"` remain text messages rather than being treated as blocks.

 A good
match?
-------------

### What we do best

- All things Laravel
- Custom frontend components
- Building APIs
- AI-powered features
- Simplifying things
- Clean solutions
- Integrating services

### Not our cup of tea

- WordPress themes
- Cutting corners
- Free mockups to win a job
- "Just execute the briefing"

 In short: we'd like to be a **substantial part** of your project.

 [ Get in touch via email ](mailto:info@spatie.be?subject=A%20good%20match%21&body=Tell%20us%20as%20much%20as%20you%20can%20about%0A-%20your%20online%20project%0A-%20your%20planning%0A-%20your%20budget%0A-%20%E2%80%A6%0A%0AAnything%20that%20helps%20us%20to%20start%20straightforward%21)
