Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Find dollar sign in a text string for adding emoji #458

Merged
merged 5 commits into from
Jun 19, 2024

Conversation

punkzberryz
Copy link
Contributor

From Easy way to add emoji to text message #456

When we want to add Emoji in text message, we use $ as a placeholder inside the text and provide the index of the $. (ref)

Function FindDollarSignIndexInUni16Text helps to identify the the dollar-sign position inside the string.

Example use case can be found in Kitchen Signk

		message := "Hello, $ hello こんにちは $, สวัสดีครับ $"
		emojiIndexes := linebot.FindDollarSignIndexInUni16Text(message)
		emojis := []messaging_api.Emoji{}
		for _, index := range emojiIndexes {
			emojis = append(emojis, messaging_api.Emoji{
				Index:     int32(index),
				ProductId: "5ac1bfd5040ab15980c9b435",
				EmojiId:   "001",
			})
		}
		result, _, err := app.bot.ReplyMessageWithHttpInfo(
			&messaging_api.ReplyMessageRequest{
				ReplyToken: replyToken,
				Messages: []messaging_api.MessageInterface{
					messaging_api.TextMessage{
						Text:   message,
						Emojis: emojis,
					},
				},
			},
		)

Example result shown in the image
IMG_4720

@CLAassistant
Copy link

CLAassistant commented Jun 15, 2024

CLA assistant check
All committers have signed the CLA.

Copy link
Contributor

@Yang-33 Yang-33 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you, @punkzberryz ! Almost all looks good to me. Let me leave minor comments. After fixing minors, this change will be released as v8.7.0!

examples/kitchensink/server.go Outdated Show resolved Hide resolved
linebot/find_dollar_sign.go Outdated Show resolved Hide resolved
Comment on lines 12 to 15
bytes := utf16.Encode([]rune(text))
for i := range bytes {

if bytes[i] == 36 {
Copy link
Contributor

@Yang-33 Yang-33 Jun 18, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To clarify 36 is $, how about this?

Suggested change
bytes := utf16.Encode([]rune(text))
for i := range bytes {
if bytes[i] == 36 {
encoded := utf16.Encode([]rune(text))
for i, unit := range encoded {
if unit == '$' {

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The value unit itself is actually value 36. Because the value has been encoded.

But I see your point. So I will do this instead:

type CharInUTF16 uint16

const dollarSign CharInUTF16 = 36

...

encoded := utf16.Encode([]rune(text))
	for i, unit := range encoded {

		if unit == uint16(dollarSign) {

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks!

@Yang-33 Yang-33 linked an issue Jun 18, 2024 that may be closed by this pull request
@punkzberryz punkzberryz force-pushed the find_dollar_sign branch 2 times, most recently from 8edfa94 to a21cb7f Compare June 19, 2024 03:16
Copy link
Contributor

@Yang-33 Yang-33 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you, @punkzberryz !

@Yang-33 Yang-33 merged commit 955fcb7 into line:master Jun 19, 2024
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Easy way to add emoji to text message
3 participants