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

add parser for URL that returns image #12

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

ronaudinho
Copy link
Contributor

@ronaudinho ronaudinho commented Oct 7, 2020

Description

#2

  • if pesan contains image(s), reply will be image(s) with caption
  • if pesan contains image(s) and json URL, caption will contain parsed JSON response
  • if there are more than 1 images, only image from the last URL is captioned

a lot of changes are whitespace changes made by my linter when working on your existing code.

Type of change

  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)

see comments on code for details on possible breaking changes.

How Has This Been Tested?

  • run testserver at cmd/testserver i.e go run cmd/testserver/main.go from repo root
  • go test -run TestNemoParser to run changes specific to this commit

Checklist:

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • Any dependent changes have been merged and published in downstream modules

- if pesan contains image(s), reply will be image(s) with caption
- if pesan contains image(s) and json URL, caption will contain parsed JSON response
- if there are more than 1 images, only image from the last URL is
captioned
if reply != "timeout" {
go sendMessage(wh.c, reply, message.Info.RemoteJid)
// non-nil txt indicates is it a text message
if txt != nil {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

does not rewrite reply even if message is parsed successfully, I think the next process has separate logic for determining reply status. should not affect your current code but this might be breaking.

testURL1, testURL2, testURL3 string
testTextURL1 = testBaseURL + "/text/1"
testTextURL2 = testBaseURL + "/text/2"
testImageURL1 = testBaseURL + "/image/1"
)

func TestNemoParser(t *testing.T) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

change the testing process

@k1m0ch1 k1m0ch1 self-requested a review October 7, 2020 13:27
@k1m0ch1
Copy link
Collaborator

k1m0ch1 commented Oct 7, 2020

I'll review this, thank you for helpin us.

@ronaudinho
Copy link
Contributor Author

@k1m0ch1 sure thing, let me know if you have any question

Copy link
Collaborator

@k1m0ch1 k1m0ch1 left a comment

Choose a reason for hiding this comment

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

Hi thank you for contribute to this project, I just test your code, and here is some problem in the comment
I think you only need to fix that I commented,
If you hardly solve the problem, let me know, I'll still merge this PR and pair with my team.

// non-nil txt indicates is it a text message
if txt != nil {
go sendMessage(wh.c, txt.Text, message.Info.RemoteJid)
return
Copy link
Collaborator

Choose a reason for hiding this comment

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

@ronaudinho I think this will make the bot stop and didn't continue to ask the questions

Copy link
Collaborator

Choose a reason for hiding this comment

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

here is when using return
image
and here is without return
image

}

wac.Presence(RJID, whatsapp.PresenceComposing)
msgId, err := wac.Send(msg)
Copy link
Collaborator

Choose a reason for hiding this comment

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

@ronaudinho I have this kind of bug from another bot that I develop by sending image the wac.send(msg) always returned

error sending message: message sending responded with %!d(float64=400)

I'm using this image https://miro.medium.com/max/356/1*EnF9uIN_u2_X7ey24lB7Tg.png
weirldly return "blank" like this
image

Info: whatsapp.MessageInfo{
RemoteJid: RJID,
},
Caption: img.Caption,
Copy link
Collaborator

Choose a reason for hiding this comment

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

@ronaudinho this will be much better if the caption from the text message
like example if the coral have commands message

...
     message: "Let's start how cool you are {{https://miro.medium.com/max/356/1*EnF9uIN_u2_X7ey24lB7Tg.png}} man"
...

so this will returned "Let's start how cool you are man"

@k1m0ch1
Copy link
Collaborator

k1m0ch1 commented Oct 15, 2020

@ronaudinho also, can you resolve the conflict? it's simple if condition

@ronaudinho
Copy link
Contributor Author

sorry i'm a little bit busy at the moment, will try to take a look at it on the weekend

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants