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

[New Feature] FriendRequest class and event #33

Closed
huan opened this issue Oct 2, 2016 · 9 comments
Closed

[New Feature] FriendRequest class and event #33

huan opened this issue Oct 2, 2016 · 9 comments
Assignees
Milestone

Comments

@huan
Copy link
Member

huan commented Oct 2, 2016

according to #14

WxApp

class contactFactory {
  verifyUser({
      UserName: string
      , Opcode: confFactory.VERIFYUSER_OPCODE_VERIFYOK
      , Scene: confFactory.ADDSCENE_PF_WEB
      , Ticket: Ticket
      , VerifyContent: string
  })
}

type RecommendInfo = {
  UserName: string
  NickName: string
  Content:     string // request message
  Ticket:         string // a pass token
  VerifyFlag:  number
}

interface Message = {
  RecommendInfo: RecommendInfo
}

Wechaty Class FriendRequest

  1. send request to other
  2. receive request from other(in friend event)
class FriendRequest {
  private info: RecommentInfo
  private hello: string
  private ticket: string

  private contact: Contact

  constructor(): FriendRequest

  send(contact: string|Contact, hello?: string): Promise<any> // 1. send friend request to other
  receive(info?: RecommendInfo): FriendRequest    // 2. receive request from other

  accept(): Promise<any>
}

Interface Wechaty {
  on('friend', (contact: Contact, request: FriendRequest) => void): void
}

Add Friend / Send Friend Request

accept friend requirest interface should be like this:

const sender : Contact = message.get('from')
const fr = new FriendRequest()
fr.send(sender, 'hello~')

Event: Friend Request

  1. Receive New Friend Request
  2. Confirmation of FriendShip

friend request is a message from SP_CONTACT_RECOMMEND_HELPER: "fmessage", with type Message.Type.VERIFYMSG

in PuppetWeb.onServerMessage():

if (message.MsgType === MSGTYPE_VERIFYMSG) {
  const request = new FriendRequest()
  request.receive(message.RecommendInfo)
  emit('friend', request.contact, request)
}

// Be Accepted: I've accepted your friend request. Now let's chat!
// Accept: You have added ${NickName} as your WeChat contact. Start chatting!
case Message.Type.SYS:
if (/^You have added (. ) as your WeChat contact. Start chatting!$/.test(m.get('content'))) {
const request = new FriendRequest()
  const contact = Contact.load(m.get('from'))
  request.confirm(contact)

  this.emit('friend', contact)
}

then we can:

wechaty.on('friend', (contact, request) => {
  if (request) { // 1. we got new request
    if (/secret/.test(request.hello)) {
      request.accept()
    }
  } else { // 2. we got new friend
    console.log('got new friend: '   contact)
  }
})
@huan
Copy link
Member Author

huan commented Oct 4, 2016

all done. :)

@JasLin
Copy link
Contributor

JasLin commented Oct 7, 2016

great job,

const sender : Contact = message.get('from')
const fr = new FriendRequest()
fr.send(sender, 'hello~')

so, now we can add friend in rooms ,just instance a Contact from room.memberList?

and ,has any idea to add friend with a giving wechat number?

@huan
Copy link
Member Author

huan commented Oct 8, 2016

Yes, we have to get the sender contact from either the room.memberList or the message.from() from a message(in case you allow stranger to chat with you).

there's no way to add a friend via their wechat number, because wechat web api did not support that.

you can check this by login wechat web wx.qq.com by your wechat account. if you can find how to add friend with a giving wechat number, please let me know. thanks. :)

@huan huan reopened this Oct 8, 2016
@JasLin
Copy link
Contributor

JasLin commented Oct 8, 2016

may be we should puppet the android version wechat , puppetAndroid :)

@huan
Copy link
Member Author

huan commented Oct 8, 2016

@JasLin wow... you caught me...

how do you think? we could use webdriver/appium to puppet the wechat app in android/ios, through the emulator. and the emulator can run inside docker, so there will be no difficaulty to use(even the environment will be more complex than now).

but I'm afraid recently I have no time to start this. if you are familar with the emulator, you are definitely welcome to have a try with PuppetAndroid!

@JasLin
Copy link
Contributor

JasLin commented Oct 9, 2016

@zixia it could be very complex , forget it , just a joke :)
tencent do not allow us to use wechat in emulator, it would cost much time to hack it

@huan
Copy link
Member Author

huan commented Oct 9, 2016

@JasLin I think maybe it's not that complex...

i.e. inject code to wechat as root, to skip the emulator check function in wechat?

I don't know exactly, hope somebody will come someday, get it done. then everything will work like a charm. ;-) (I believe somebody is already do that: run wechaty inside emulator)

Here's some link for run wechat inside emulator:

@JasLin
Copy link
Contributor

JasLin commented Oct 9, 2016

@zixia yes, somebody is already do that:)
for andoird , it could use AccessibilityService to simulate click action.

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

No branches or pull requests

2 participants