Skip to content

Commit

Permalink
Merge pull request #111 from codigoencasa/master
Browse files Browse the repository at this point in the history
Stuff
  • Loading branch information
leifermendez authored Apr 7, 2024
2 parents 7a01ea9 + 4f2f45a commit 7883f32
Show file tree
Hide file tree
Showing 15 changed files with 639 additions and 58 deletions.
Binary file added public/assets/examples/contactsOnBot.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/assets/examples/deleteBotMessage1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/assets/examples/deleteBotMessage2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/assets/examples/imageProfile.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/assets/examples/status.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
14 changes: 14 additions & 0 deletions src/pages/en/databases/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,20 @@ main()

[PostgreSQL](https://www.postgresql.org/) database, celebrated for its reliability and cutting-edge features, presents formidable data storage solutions for bot-generated responses. Seamless integration with PostgreSQL entails specifying vital parameters such as `host`, `user`, `password`, `database` name, and `port`. This database variant guarantees data integrity and scalability, rendering it optimal for applications requiring top-tier data storage and retrieval performance.


### Uses Cases

If you want connect your bot to cloud database like Supabase or any CloudProvider you can use it.
<div className="not-prose aling-block">
<Button
href="/databases/postgres/uses-cases"
variant="text"
arrow="right"
children="More info about Postgres connection uses cases"
/>
</div>


PostgreSQL's flexible architecture and endorsement of advanced data types empower developers to craft sophisticated bots endowed with extensive functionality. Leveraging PostgreSQL equips developers with potent querying capabilities, transactional support, and comprehensive data management features, fostering the creation of resilient and efficient bot systems.

<CodeGroup>
Expand Down
21 changes: 21 additions & 0 deletions src/pages/en/databases/postgres/uses-cases/index.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { Contributors } from '@/components/Contributors'
import { Resources } from '@/components/Resources'
import { Guides } from '@/components/Guides'

export const description =
'In this guide, we will discuss what to do to connecting another database.'

# Supabase Uses Cases


<Contributors mode users={['elimeleth']} />

Connect to your Cloud Supabase database
<div className="not-prose aling-block">
<Button
href="/databases/postgres/uses-cases/uses-cases-supabase"
variant="text"
arrow="right"
children="More info about Supabase connection uses cases"
/>
</div>
45 changes: 45 additions & 0 deletions src/pages/en/databases/postgres/uses-cases/uses-cases-supabase.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import { Contributors } from '@/components/Contributors'
import { Resources } from '@/components/Resources'
import { Guides } from '@/components/Guides'

export const description =
'In this guide, we will discuss what to do to connecting another database.'

# Getting Starter


<Contributors mode users={['elimeleth']} />



Postgres database supports other types of connections as in this case it is Supabase, let's take a quick tour on the Supabase platform to get our database credentials

The first thing is to create your account if you don't have one yet [Supabase](https://supabase.com/dashboard/sign-in?returnTo=%2Fsign-in) account.
Log in with your Github user

<Image src="https://i.imgur.com/P6b9jtU.jpg" />

The second thing is to create an organization which is the one that allows you to create projects, this part is intuitive, create one then the other
The database will ask you for a strong key, copy it and save it in a safe place, you will need it later for the connection :)

<Image src="https://i.imgur.com/BJNpXbv.jpg" />

Once we have our database ready, the next thing is to go to the project configuration section

<Image src="https://i.imgur.com/4s5LRvF.jpg" />

when clicking on database we will see all our configuration, you must copy each one do not forget that the key is the same when creating the project

<Image src="https://i.imgur.com/ZovUQLz.jpg" />

at the end you should be able to configure your database as follows

<Image src="https://i.imgur.com/BSQEPsX.png" />

<Image src="https://i.imgur.com/gCPzk3C.png" />
----

<Guides />

<Resources />

2 changes: 1 addition & 1 deletion src/pages/en/methods/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ flowchart LR

## State/GlobalState Options {{ not:'true' }}

Both methods such as state and global estate contain similar options and funcinalides, which depending on the use case can be very useful.
Both methods such as state and global state contain similar options and funcinalides, which depending on the use case can be very useful.

## Clear {{ not:'true' }}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,19 @@ import { Resources } from '@/components/Resources'
import { Guides } from '@/components/Guides'


# Presence Update

This method lets the person/group with id know whether you're online, offline, typing etc.


```
(property) sendPresenceUpdate: (type: WAPresence, toJid?: string) => Promise<void>
```

WAPresence can be one of the following:
# Delete Bot Message

We can use the <strong>sendMessage</strong> method to delete a message sent by the bot. This method has the following signature:
```
type WAPresence = 'unavailable' | 'available' | 'composing' | 'recording' | 'paused'
(property) sendMessage: (jid: string, content: AnyMessageContent, options?: MiscMessageGenerationOptions) => Promise<proto.WebMessageInfo>
```

<Contributors mode users={['jorgechavarriaga']} />

```ts {{ title: 'app.ts' }}
import { createBot, createProvider, createFlow, addKeyword, EVENTS } from '@builderbot/bot'
import { MemoryDB as Database } from '@builderbot/bot'
import { BaileysProvider as Provider } from '@builderbot/provider-baileys'
import { MemoryDB as Database } from '@builderbot/bot'
import { config } from 'dotenv'
config()

Expand All @@ -38,15 +30,15 @@ const waitT = (ms: number) => {
}

const welcomeFlow = addKeyword<Provider, Database>(EVENTS.WELCOME)
.addAnswer(`💡 Example *Sending Presence Update*`)
.addAnswer(`💡 Example delete Message`)
.addAction(
async (ctx, { provider, flowDynamic }) => {
await flowDynamic('This is an example of presence update')
await provider.vendor.sendPresenceUpdate('recording', ctx.key.remoteJid)
await waitT(5000)
await provider.vendor.sendPresenceUpdate('composing', ctx.key.remoteJid)
const number = ctx.key.remoteJid
await provider.vendor.sendMessage(number, { text: `Next message is going to be deleted in 5 seconds.\n\n*${Date()}*` })
const msg = await provider.vendor.sendMessage(number, { text: `This is the message to be deleted!!! ` })
await waitT(5000)
await flowDynamic('Great!')
await provider.vendor.sendMessage(number, { delete: msg.key })
await flowDynamic(`*${Date()}*\n\nMessage has been deleted!`)
}
)

Expand All @@ -61,15 +53,15 @@ const main = async () => {
database: adapterDB,
}
)

}

main()

```
<iframe style={{minWidth: '800px', minHeight: '480px'}} src="https://www.youtube.com/embed/lknNwerosHQ?autoplay=1&loop=1" title="YouTube video player" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" ></iframe>


<img style={{minHeight:'450px'}} className="rounded-2xl bg-zinc-900 w-full shadow-md dark:ring-1 dark:ring-white/10" src="/assets/examples/deleteBotMessage1.png" alt="API Call Example" />
<img style={{minHeight:'450px'}} className="rounded-2xl bg-zinc-900 w-full shadow-md dark:ring-1 dark:ring-white/10" src="/assets/examples/deleteBotMessage2.png" alt="API Call Example" />

---

<Guides />
Expand Down
106 changes: 106 additions & 0 deletions src/pages/en/providers/baileys/delete-on-bot.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
import { Contributors } from '@/components/Contributors'
import { Resources } from '@/components/Resources'
import { Guides } from '@/components/Guides'


# Contacts on BOT

From the adapterProvider, we can utilize the store property to fetch all contacts, store them in a variable, and subsequently display them to the user. This property has the following signature:

```
(property) BaileysProvider.store?: {
chats: KeyedDB<Chat, string>;
contacts: {
[_: string]: Contact;
};
messages: {
[_: string]: {
array: proto.IWebMessageInfo[];
get: (id: string) => proto.IWebMessageInfo;
... 7 more ...;
fromJSON: (newItems: proto.IWebMessageInfo[]) => void;
};
};
... 18 more ...;
readFromFile: (path: string) => void;
}
```
<strong>Contact</strong> structure:
```
Contact {
id: string;
lid?: string;
name?: string;
notify?: string;
verifiedName?: string;
imgUrl?: string | null | 'changed';
status?: string;
}
```

<Contributors mode users={['jorgechavarriaga']} />

```ts {{ title: 'app.ts' }}
import { createBot, createProvider, createFlow, addKeyword, EVENTS } from '@builderbot/bot'
import { BaileysProvider as Provider } from '@builderbot/provider-baileys'
import { MemoryDB as Database } from '@builderbot/bot'
import { config } from 'dotenv'
config()

const PHONE_NUMBER = process.env.PHONE_NUMBER
let contacts = {}

const welcomeFlow = addKeyword<Provider, Database>(EVENTS.WELCOME)
.addAnswer(`💡 Example *Contacts on BOT*`)
.addAction(
async (_, { flowDynamic }) => {
const contactsBot = Object.entries(contacts)
.map(([id, data]) => ({ id, name: data }))
await flowDynamic(`Total contacts: ${contactsBot.length}`)
const messages: string[] = []
for (const grupo of contactsBot) {
const message = `${grupo.name ? 'Object:' : ''} ${JSON.stringify(grupo?.name, null, 5) || ''}\n*id:* ${grupo.id}`
messages.push(message);
}
const concatenatedMessages = messages.join('\n\n')
await flowDynamic(concatenatedMessages);
}
)

const main = async () => {
const adapterFlow = createFlow([welcomeFlow])

const adapterProvider = createProvider(Provider, { usePairingCode: true, phoneNumber: PHONE_NUMBER })
const adapterDB = new Database()

const { handleCtx, httpServer } = await createBot(
{
flow: adapterFlow,
provider: adapterProvider,
database: adapterDB,
}
)

try {
adapterProvider.on("ready", () => {
if (adapterProvider.store && adapterProvider.store.contacts) {
contacts = adapterProvider.store.contacts
}
})
} catch (error) {
console.log(error)
}
}

main()

```


<img style={{minHeight:'450px'}} className="rounded-2xl bg-zinc-900 w-full shadow-md dark:ring-1 dark:ring-white/10" src="/assets/examples/contactsOnBot.png" alt="API Call Example" />

---

<Guides />

<Resources />
Original file line number Diff line number Diff line change
Expand Up @@ -3,49 +3,42 @@ import { Resources } from '@/components/Resources'
import { Guides } from '@/components/Guides'


# Number on Whatsapp

To check if an entered number exists on WhatsApp, you use the 'onWhatsApp' method of the provider. This method has the following signature:
# Fetch Status

This method has the following signature:
```
onWhatsApp: (...jids: string[]) => Promise<{
exists: boolean;
jid: string;
}[]>
(property) fetchStatus: (jid: string) => Promise<{
status: string;
setAt: Date;
}>
```

This method accepts one or more phone numbers (JIDs) as arguments and returns a promise that resolves to an array of objects containing
the existence status (exists) and JID (jid) for each number.

<Contributors mode users={['jorgechavarriaga']} />

```ts {{ title: 'app.ts' }}
import { createBot, createProvider, createFlow, addKeyword, EVENTS } from '@builderbot/bot'
import { MemoryDB as Database } from '@builderbot/bot'
import { BaileysProvider as Provider } from '@builderbot/provider-baileys'
import { MemoryDB as Database } from '@builderbot/bot'
import { config } from 'dotenv'
config()

const PHONE_NUMBER = process.env.PHONE_NUMBER

const welcomeFlow = addKeyword<Provider, Database>(EVENTS.WELCOME)
.addAnswer(`💡 Example *Number Exist on Whatsapp*`)
.addAnswer(
'*Enter the number to check:*',
.addAnswer(`💡 Example *Whatsapp Status*`)
.addAction(
async (_, { provider, flowDynamic }) => {
const statusInfo = await provider.vendor.fetchStatus(PHONE_NUMBER + '@s.whatsapp.net')
console.log(statusInfo)
await flowDynamic(`*Status Info for ${PHONE_NUMBER}*:\n\nStatus: *${statusInfo.status}*\nSet At: ${statusInfo.setAt}`)
await flowDynamic(`Enter phone number to check status:`)
}
)
.addAction(
{ capture: true },
async (ctx, { provider, flowDynamic }) => {
const checkNumber = ctx.body
try {
const onWhats = await provider.vendor.onWhatsApp(checkNumber)
if (onWhats[0]?.exists) {
await flowDynamic([`*Exists:* ${onWhats[0].exists}\n*JID:* ${onWhats[0].jid}`, `*Object:* ${JSON.stringify(onWhats, null, 6)}`])
}
else {
await flowDynamic(`The number *${checkNumber}* does not exists on Whatsapp.`)
}
} catch (error) {
await flowDynamic(`*Error:* ${error}`);
}
const statusR = await provider.vendor.fetchStatus(ctx.body + '@s.whatsapp.net')
await flowDynamic(`*Status for:* ${ctx.body}\n\nStatus: *${statusR.status}*\nSet At: ${statusR.setAt}`)
}
)

Expand All @@ -63,11 +56,10 @@ const main = async () => {
}

main()

```

<img style={{minHeight:'450px'}} className="rounded-2xl bg-zinc-900 w-full shadow-md dark:ring-1 dark:ring-white/10" src="/assets/examples/status.png" alt="API Call Example" />

<img style={{minHeight:'450px'}} className="rounded-2xl bg-zinc-900 w-full shadow-md dark:ring-1 dark:ring-white/10" src="/assets/examples/onWhatsapp.png" alt="API Call Example" />
---

<Guides />
Expand Down
Loading

0 comments on commit 7883f32

Please sign in to comment.