Skip to content

Commit

Permalink
Fix: integration code snippet (#462)
Browse files Browse the repository at this point in the history
  • Loading branch information
sohamganatra authored Aug 19, 2024
1 parent 24e041c commit 77bb492
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 16 deletions.
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
---
title: "🔧 Crafting Custom Tools"
sidebarTitle: "Custom Tools"
title: "🔧 Custom Tools Using OpenAPI Spec"
sidebarTitle: "OpenAPI Tools"
icon: "puzzle-piece"
description: "Explore the process of creating custom integrations with external Apps"
description: "Explore the process of creating custom tools with external Apps using OpenAPI Spec"
---

Creating custom tools on Composio is straightforward and can be done via an [OpenAPI Spec](https://swagger.io/specification/). Here's a quick video on how you can add a custom integration to Composio using OpenAPI Spec.
Expand Down Expand Up @@ -302,8 +302,4 @@ Navigate back to the tools catalogue page on Composio. Search for the tool you j

</Step>

</Steps>

If you face any issues or found any bugs, join our <a href="https://dub.composio.dev/discord">Discord</a> to chat with the team or write to us at [email protected].

You can also add the actions to your custom tools. Click on the next article to read on how to create actions for your custom tool.
</Steps>
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,73 @@ description: "Allow your users to connect with any Apps."

## Overview of Integrations

Integrations allow users to link their accounts with external apps, enabling agents to take actions on their behalf. You can view all active integrations and monitor live connections or users by visiting the [Dashboard](https://app.composio.dev/your_apps).
Integrations allow users to link their accounts with external apps, enabling agents to take actions on their behalf.

Integrations are tool configurations (eg. Permissions to ask for when connecting an account, ClientID/Secret in the case of OAuth) that will be used to connect your users account to Composio. You can use your own configuration or use Composio's default integrations.
You can view all active integrations and monitor live connections or users by visiting the [Dashboard](https://app.composio.dev/your_apps).

Once an integration is established, it can be utilized by an **unlimited number of users** to connect their accounts. So ideally you will only build **one integration per tool or application** and **allow all your users to connect using it**.
Integrations are tool configurations (eg. Permissions to ask for when connecting an account, ClientID/Secret in the case of OAuth) that will be used to connect your users account to Composio.

To authenticate users with a specific tool, create a new integration by selecting the desired tool on the [Tools Page](https://app.composio.dev/apps). Integrations can be established using either default credentials or by registering a new developer application and setting the necessary authentication and permission scopes.
You can use your own configuration or use Composio's default integrations.

Once an integration is established, it can be utilized by an **unlimited number of users** to connect their accounts.

So ideally you will only build **one integration per tool or application** and **allow all your users to connect using it**.


## Using Integration ID to Connect an Account for a user
<Tabs>
<Tab title="Python">
<CodeGroup>
```python Connect a User's account using Integration ID
from composio import ComposioToolSet, App
from composio.client.exceptions import NoItemsFound

toolset = ComposioToolSet()

entity_id = "Jessica" # change this with your user_id
integration_id = "integration_id"

entity = toolset.get_entity(id=entity_id)

integration = toolset.client.integrations.get_by_id(integration_id=integration_id)


try:
connection = entity.get_connection(app=App.GITHUB)
# Connection Already exist with Github.
# Now we can check if it's using the correct integration

if connection:
connection_integration_id = connection.integrationId
if connection_integration_id == integration_id:
# Connection is already active with the correct integration
print(f"User is already authenticated with GitHub")
else:
# Connection is active with a different integration
# TODO: Choose between the following options:
# 1. Create a new connection with the correct integration
# 2. Ignore as it's fine
print(f"User is already authenticated with GitHub but with a different integration")

print(f"User is already authenticated with GitHub")

except NoItemsFound as e:
# Create a request to initiate connection
request = entity.initiate_connection(App.GITHUB,integration=integration)

print(
f"Please authenticate {App.GITHUB} in the browser and come back here. URL: {request.redirectUrl}"
)

# Poll until the connection is active
connected_account = request.wait_until_active(client=toolset.client, timeout=100)
```
</CodeGroup>
</Tab>
<Tab title="JavaScript">
coming soon!
</Tab>
<Tab title="API">
coming soon!
</Tab>
</Tabs>
7 changes: 3 additions & 4 deletions docs/mint.json
Original file line number Diff line number Diff line change
Expand Up @@ -90,14 +90,13 @@
"introduction/foundations/components/actions/action-guide",
"introduction/foundations/components/triggers/trigger-guide",
"introduction/foundations/components/local_tools",
"introduction/foundations/components/integrations/custom-integration",
{
"group": "Advanced",
"pages": [
"introduction/foundations/components/actions/processing",
"introduction/foundations/components/integrations/integration-guide",
"introduction/foundations/components/workspace",
"introduction/foundations/components/integrations/custom-integration"

"introduction/foundations/components/actions/processing",
"introduction/foundations/components/workspace"
]
}
]
Expand Down

0 comments on commit 77bb492

Please sign in to comment.