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

Friend request #981

Merged
merged 37 commits into from
Nov 20, 2021
Merged
Show file tree
Hide file tree
Changes from 15 commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
20de3aa
Added friendship event
abhishek-iiit Jun 27, 2021
dc90fc7
0.8.303
abhishek-iiit Jun 27, 2021
713e7d1
0.8.304
abhishek-iiit Jun 27, 2021
f61e3db
0.8.305
abhishek-iiit Jun 27, 2021
ecfa802
added changes
abhishek-iiit Jul 3, 2021
368df1f
0.8.306
abhishek-iiit Jul 3, 2021
b9bf8e7
Merge branch 'master' into friend_request
abhishek-iiit Jul 5, 2021
47e685a
Merge branch 'master' into friend_request
lijiarui Jul 10, 2021
e3b64d3
removed image as suggested
abhishek-iiit Jul 25, 2021
c18b21e
0.8.314
abhishek-iiit Jul 25, 2021
4c2da96
Merge branch 'master' into friend_request
abhishek-iiit Jul 25, 2021
b7d6ac1
Merge branch 'master' of https://github.com/abhishek-iiit/wechaty.js.…
abhishek-iiit Jul 25, 2021
3476326
0.8.329
abhishek-iiit Jul 25, 2021
d976f1f
0.8.330
abhishek-iiit Jul 25, 2021
9b58d90
0.8.331
abhishek-iiit Jul 25, 2021
c88f381
Merge branch 'master' into friend_request
abhishek-iiit Sep 10, 2021
63deb25
Merge branch 'master' into friend_request
huan Sep 10, 2021
bb0a5a5
Merge branch 'master' into friend_request
abhishek-iiit Sep 16, 2021
5b1f687
Merge branch 'master' of https://github.com/abhishek-iiit/wechaty.js.…
abhishek-iiit Sep 16, 2021
2113802
added links
abhishek-iiit Sep 16, 2021
695b1c0
0.10.9
abhishek-iiit Sep 16, 2021
26c478c
Merge branch 'friend_request' of https://github.com/abhishek-iiit/wec…
abhishek-iiit Sep 16, 2021
e48d06e
0.10.10
abhishek-iiit Sep 16, 2021
def4d91
version change
abhishek-iiit Sep 21, 2021
d0d5ac9
Merge branch 'master' of https://github.com/abhishek-iiit/wechaty.js.…
abhishek-iiit Sep 21, 2021
d32d282
added files
abhishek-iiit Sep 21, 2021
1b7e3ac
0.10.14
abhishek-iiit Sep 21, 2021
35ba5d0
Merge branch 'master' into friend_request
Rohitesh-Kumar-Jain Sep 24, 2021
8064702
Merge branch 'main' into friend_request
Rohitesh-Kumar-Jain Oct 16, 2021
d99f7c5
Merge branch 'main' into friend_request
abhishek-iiit Oct 24, 2021
f3f002e
added suggested link
abhishek-iiit Oct 24, 2021
93ba27a
0.10.28
abhishek-iiit Oct 24, 2021
a45b058
Merge branch 'main' into friend_request
abhishek-iiit Oct 24, 2021
db92cc4
Merge branch 'main' into friend_request
Rohitesh-Kumar-Jain Nov 3, 2021
4142913
Merge branch 'main' into friend_request
shraddhavp Nov 14, 2021
e6d05a3
Merge branch 'main' into friend_request
abhishek-iiit Nov 17, 2021
1298a54
Merge branch 'main' into friend_request
shraddhavp Nov 20, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,11 +1,32 @@
---
title: 'Making friends'
title: 'Send and accept friend requests'
---

import Tabs from '@theme/Tabs'
import TabItem from '@theme/TabItem'

## Sending Request
Sending and accepting friend requests can easily be done using wechaty `onfriendship` function. This guide will help you send request, receive request(in friend event), confirm friendship(friend event) in a room.

Use the guide to help you integrate additional functions to an existing project which is present at [Github/Friend-Bot](https://github.com/wechaty/wechaty/blob/1523c5e02be46ebe2cc172a744b2fbe53351540e/examples/friend-bot.ts) or check that your existing local system will run on Wechaty. If, you wish to learn on how to build the bot on your own, please visit one of our [Building the bot](https://wechaty.js.org/docs/examples/basic/contact-bot#building-the-bot) section.
shraddhavp marked this conversation as resolved.
Show resolved Hide resolved

The steps outlined here mainly focuses on working with Javascript, but user are free to switch between any languages.This guide help you Send, receive friend request, and friend confirmation events.

## Prerequisites

* Your system must have [Node.js](https://nodejs.org/en/download/package-manager/) installed (version >= 12).
shraddhavp marked this conversation as resolved.
Show resolved Hide resolved
* Your system must have [Wechaty](https://github.com/wechaty/wechaty) (version >= 0.40).
* You need to be familiar with the basics of Wechaty platform. If not, follow our [tutorials](https://wechaty.js.org/docs/tutorials/) section.
* You need to have at least a minimal application ready to work, follow one of our [Example/Friend-Bot](https://wechaty.js.org/docs/examples/advanced/friend-bot/).
shraddhavp marked this conversation as resolved.
Show resolved Hide resolved

### If you don't know where to start from

See [Running our first ding-dong bot](https://wechaty.js.org/docs/getting-started/quick-start).
shraddhavp marked this conversation as resolved.
Show resolved Hide resolved

The below function needs a basic script that can help run the bot. The basic script starts by importing the code from [Github/Friend-Bot](https://github.com/wechaty/wechaty/blob/1523c5e02be46ebe2cc172a744b2fbe53351540e/examples/friend-bot.ts).Integrate the below code, for this action to work.
shraddhavp marked this conversation as resolved.
Show resolved Hide resolved

## Send Request - define how to send a friend request

When you send the request, you try to make new friend connection. This section elaborates on how to send friend requests.`Friendship.search(<id>)` helps you search the contact, if found we get "Sending friend request..." as a response else "Friendship.search: not found" as a response.

<Tabs
groupId="programming-languages"
Expand Down Expand Up @@ -119,7 +140,9 @@ class MyBot(Wechaty):
</TabItem>
</Tabs>

## Receiving Request
## Receive Request - define how to accept the friend request

When someone sends you the request, you choose whether to have the friend connection or to reject the connection. This section elaborates on how to accept friend requests. When someone sends you the request, the `friendship.contact()` helps you list down all the contacts with a hello message from `friendship.hello()` and then when the user accepts the request, it prints out with a confirmation message using `friendship.contact().name()`.

<Tabs
groupId="programming-languages"
Expand All @@ -140,11 +163,11 @@ class MyBot(Wechaty):
<TabItem value="ts">

```ts
import { Friendship } from 'wechaty'
const { Friendship } = require('wechaty')
abhishek-iiit marked this conversation as resolved.
Show resolved Hide resolved

async function onFriendship (friendship: Friendship) {
if (friendship.type() === Friendship.Type.Receive) {
console.info('New requrest from', friendship.contact())
console.info('New request from', friendship.contact())
console.info('Hello message:', friendship.hello())
await friendship.accept()
} else if (friendship.type() === Friendship.Type.Confirm) {
Expand All @@ -159,11 +182,11 @@ bot.on('friendship', onFriendship)
<TabItem value="js">

```js
import { Friendship } from 'wechaty'
const { Friendship } = require('wechaty')

async function onFriendship (friendship) {
if (friendship.type() === Friendship.Type.Receive) {
console.info('New requrest from', friendship.contact())
console.info('New request from', friendship.contact())
console.info('Hello message:', friendship.hello())
await friendship.accept()
} else if (friendship.type() === Friendship.Type.Confirm) {
Expand Down
2 changes: 1 addition & 1 deletion docusaurus/docs/howto/overview.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ These are some use cases and code snippets to get you started with Redux in a re
- [Dealing with messages](howto/message.md)
- [Managing contacts](howto/contact.md)
- [Managing rooms](howto/room.md)
- [Making friends](howto/friendship.md)
- [Making friends](howto/friendship.mdx)
- [Processing files](howto/file-box.md)

## Using Puppets with Wechaty (How to switch between puppets)
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "wechaty.js.org",
"version": "0.8.328",
"version": "0.8.331",
"description": "Wechaty Official Website for News, Blogs, Contributor Profiles, and Documentations",
"private": true,
"directories": {
Expand Down