-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #111 from codigoencasa/master
Stuff
- Loading branch information
Showing
15 changed files
with
639 additions
and
58 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
45
src/pages/en/databases/postgres/uses-cases/uses-cases-supabase.mdx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 /> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 /> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.