Skip to content

Commit 6f49e2b

Browse files
authored
Merge pull request #318 from dblock/character-encoding
Document character encoding, closes #317 and #314.
2 parents 156ab7b + 65eb386 commit 6f49e2b

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

README.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ A Ruby client for the Slack [Web](https://api.slack.com/web), [RealTime Messagin
3131
- [Other](#other)
3232
- [Web Client Options](#web-client-options)
3333
- [Pagination Support](#pagination-support)
34+
- [Character Encoding](#character-encoding)
3435
- [Error Handling](#error-handling)
3536
- [Slack Errors](#slack-errors)
3637
- [Rate Limiting](#rate-limiting)
@@ -276,6 +277,24 @@ end
276277
all_members # many thousands of team members retrieved 10 at a time
277278
```
278279

280+
#### Character Encoding
281+
282+
Note that Slack expects `text` to be UTF-8 encoded. If your messages appear with text such as `BAD+11` in Slack, check `text.encoding` and `.encode(Encoding::UTF_8)` your messages before sending them to Slack.
283+
284+
```ruby
285+
text = 'characters such as "Ñ", "Á", "É"'
286+
text.encoding
287+
=> #<Encoding:UTF-8>
288+
client.chat_postMessage(channel: '#general', text: text, as_user: true)
289+
# renders 'characters such as "Ñ", "Á", "É"' in Slack
290+
291+
text = text.encode(Encoding::ISO_8859_1)
292+
text.encoding
293+
# => #<Encoding:ISO-8859-1>
294+
client.chat_postMessage(channel: '#general', text: text, as_user: true)
295+
# renders 'characters such as "BAD+11", "", "BAD+9"' in Slack
296+
```
297+
279298
#### Error Handling
280299

281300
##### Slack Errors

0 commit comments

Comments
 (0)