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

Added filters in the webhooks #1140

Merged
merged 37 commits into from
Aug 31, 2023
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
4e62d61
fix
rounak610 Aug 11, 2023
97cbc07
webhooks frontend + api calls complete almost
namansleeps2 Aug 21, 2023
ee53fd0
Merge remote-tracking branch 'origin/dev' into dev
rounak610 Aug 22, 2023
1b1a12e
webhooks compplete frontend
namansleeps2 Aug 23, 2023
8655121
Merge branch 'dev' of https://github.com/TransformerOptimus/SuperAGI …
rounak610 Aug 28, 2023
9f52ebd
Merge branch 'dev' of https://github.com/TransformerOptimus/SuperAGI …
rounak610 Aug 28, 2023
3d180f3
added filters in the webhooks
rounak610 Aug 28, 2023
898d40f
fix
rounak610 Aug 28, 2023
5d63f8f
added filters in the webhooks
rounak610 Aug 28, 2023
dc84435
Merge branch 'dev' of github.com:TransformerOptimus/SuperAGI into web…
namansleeps2 Aug 29, 2023
8eb134e
added filters in the webhooks
rounak610 Aug 29, 2023
7d90ea0
Merge branch 'webhook_dev' into webhooks_new
rounak610 Aug 29, 2023
68bf955
adding of filters table and edit functionality is on the way
namansleeps2 Aug 29, 2023
d00124d
Merge remote-tracking branch 'origin/webhooks_new' into webhooks_new
namansleeps2 Aug 29, 2023
4ef811b
added filters in webhooks
rounak610 Aug 30, 2023
41180c8
Merge branch 'webhooks_new' of https://github.com/TransformerOptimus/…
rounak610 Aug 30, 2023
df718e5
added filters in webhooks
rounak610 Aug 30, 2023
1ca7e3e
minor changes
namansleeps2 Aug 30, 2023
6c0dca4
Merge branch 'webhooks_new' of github.com:TransformerOptimus/SuperAGI…
namansleeps2 Aug 30, 2023
0e15c68
webhooks complete
namansleeps2 Aug 30, 2023
ab37d67
minor changes for PR
namansleeps2 Aug 30, 2023
5c14715
minor changes for PR
namansleeps2 Aug 30, 2023
1dd9611
added filters in webhooks
rounak610 Aug 30, 2023
a382161
Merge branch 'webhooks_new' of https://github.com/TransformerOptimus/…
rounak610 Aug 30, 2023
576f31d
resolving conflicts
namansleeps2 Aug 30, 2023
5f50b66
added filters in webhooks
rounak610 Aug 30, 2023
7a29b3e
Merge branch 'webhooks_new' of https://github.com/TransformerOptimus/…
rounak610 Aug 30, 2023
eb48d88
resolving conflicts
namansleeps2 Aug 30, 2023
0ed457f
Merge remote-tracking branch 'origin/webhooks_new' into webhooks_new
namansleeps2 Aug 30, 2023
f0659e5
added filters in the webhooks
rounak610 Aug 31, 2023
7e15b6e
bug fix of prev PR
namansleeps2 Aug 31, 2023
d069216
Merge remote-tracking branch 'origin/webhooks_new' into webhooks_new
namansleeps2 Aug 31, 2023
d741fa8
added filters in webhooks
rounak610 Aug 31, 2023
62dd221
Merge branch 'webhooks_new' of https://github.com/TransformerOptimus/…
rounak610 Aug 31, 2023
1f5e6d5
added filters in the webhooks
rounak610 Aug 31, 2023
a56dbe6
added filters in the webhooks
rounak610 Aug 31, 2023
7a08bd6
Update conftest.py
Fluder-Paradyne Aug 31, 2023
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
84 changes: 84 additions & 0 deletions migrations/versions/40affbf3022b_add_filter_colume_in_webhooks.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
"""add filter colume in webhooks

Revision ID: 40affbf3022b
Revises: 5d5f801f28e7
Create Date: 2023-08-28 12:30:35.171176

"""
from alembic import op
import sqlalchemy as sa


# revision identifiers, used by Alembic.
revision = '40affbf3022b'
down_revision = '5d5f801f28e7'
branch_labels = None
depends_on = None


def upgrade() -> None:
# ### commands auto generated by Alembic - please adjust! ###
op.drop_index('ix_agent_schedule_agent_id', table_name='agent_schedule')
op.drop_index('ix_agent_schedule_expiry_date', table_name='agent_schedule')
Fluder-Paradyne marked this conversation as resolved.
Show resolved Hide resolved
op.drop_index('ix_agent_schedule_status', table_name='agent_schedule')
op.alter_column('agent_workflow_steps', 'unique_id',
existing_type=sa.VARCHAR(),
nullable=True)
op.alter_column('agent_workflow_steps', 'step_type',
existing_type=sa.VARCHAR(),
nullable=True)
op.drop_column('agent_workflows', 'organisation_id')
op.drop_index('ix_events_agent_id', table_name='events')
op.drop_index('ix_events_event_property', table_name='events')
op.drop_index('ix_events_org_id', table_name='events')
op.alter_column('knowledge_configs', 'knowledge_id',
existing_type=sa.INTEGER(),
nullable=True)
op.alter_column('knowledges', 'name',
existing_type=sa.VARCHAR(),
nullable=True)
op.alter_column('vector_db_configs', 'vector_db_id',
existing_type=sa.INTEGER(),
nullable=True)
op.alter_column('vector_db_indices', 'name',
existing_type=sa.VARCHAR(),
nullable=True)
op.alter_column('vector_dbs', 'name',
existing_type=sa.VARCHAR(),
nullable=True)
op.add_column('webhooks', sa.Column('filters', sa.JSON(), nullable=True))
# ### end Alembic commands ###


def downgrade() -> None:
# ### commands auto generated by Alembic - please adjust! ###
op.drop_column('webhooks', 'filters')
op.alter_column('vector_dbs', 'name',
existing_type=sa.VARCHAR(),
nullable=False)
op.alter_column('vector_db_indices', 'name',
existing_type=sa.VARCHAR(),
nullable=False)
op.alter_column('vector_db_configs', 'vector_db_id',
existing_type=sa.INTEGER(),
nullable=False)
op.alter_column('knowledges', 'name',
existing_type=sa.VARCHAR(),
nullable=False)
op.alter_column('knowledge_configs', 'knowledge_id',
existing_type=sa.INTEGER(),
nullable=False)
op.create_index('ix_events_org_id', 'events', ['org_id'], unique=False)
op.create_index('ix_events_event_property', 'events', ['event_property'], unique=False)
op.create_index('ix_events_agent_id', 'events', ['agent_id'], unique=False)
op.add_column('agent_workflows', sa.Column('organisation_id', sa.INTEGER(), autoincrement=False, nullable=True))
op.alter_column('agent_workflow_steps', 'step_type',
existing_type=sa.VARCHAR(),
nullable=False)
op.alter_column('agent_workflow_steps', 'unique_id',
existing_type=sa.VARCHAR(),
nullable=False)
op.create_index('ix_agent_schedule_status', 'agent_schedule', ['status'], unique=False)
op.create_index('ix_agent_schedule_expiry_date', 'agent_schedule', ['expiry_date'], unique=False)
op.create_index('ix_agent_schedule_agent_id', 'agent_schedule', ['agent_id'], unique=False)
# ### end Alembic commands ###
3 changes: 2 additions & 1 deletion superagi/controllers/webhook.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ class WebHookIn(BaseModel):
name: str
url: str
headers: dict
filters: dict

class Config:
orm_mode = True
Expand Down Expand Up @@ -52,7 +53,7 @@ def create_webhook(webhook: WebHookIn, Authorize: AuthJWT = Depends(check_auth),
HTTPException (Status Code=404): If the associated project is not found.
"""
db_webhook = Webhooks(name=webhook.name, url=webhook.url, headers=webhook.headers, org_id=organisation.id,
is_deleted=False)
is_deleted=False, filters=webhook.filters)
db.session.add(db_webhook)
db.session.commit()
db.session.flush()
Expand Down
34 changes: 18 additions & 16 deletions superagi/helper/webhook_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import requests
import json
from superagi.lib.logger import logger

class WebHookManager:
def __init__(self,session):
self.session=session
Expand All @@ -18,20 +19,21 @@
org_webhooks=self.session.query(Webhooks).filter(Webhooks.org_id == org.id).all()

for webhook_obj in org_webhooks:
webhook_obj_body={"agent_id":agent_id,"org_id":org.id,"event":f"{old_status} to {curr_status}"}
error=None
request=None
status='sent'
try:
request = requests.post(webhook_obj.url.strip(), data=json.dumps(webhook_obj_body), headers=webhook_obj.headers)
except Exception as e:
logger.error(f"Exception occured in webhooks {e}")
error=str(e)
if request is not None and request.status_code not in [200,201] and error is None:
error=request.text
if error is not None:
status='Error'
webhook_event=WebhookEvents(agent_id=agent_id, run_id=agent_execution_id, event=f"{old_status} to {curr_status}", status=status, errors=error)
self.session.add(webhook_event)
self.session.commit()
if "status" in webhook_obj.filters and curr_status in webhook_obj.filters["status"]:
webhook_obj_body={"agent_id":agent_id,"org_id":org.id,"event":f"{old_status} to {curr_status}"}
error=None
request=None
status='sent'
try:
request = requests.post(webhook_obj.url.strip(), data=json.dumps(webhook_obj_body), headers=webhook_obj.headers)
except Exception as e:
logger.error(f"Exception occured in webhooks {e}")
error=str(e)

Check warning on line 31 in superagi/helper/webhook_manager.py

View check run for this annotation

Codecov / codecov/patch

superagi/helper/webhook_manager.py#L23-L31

Added lines #L23 - L31 were not covered by tests
if request is not None and request.status_code not in [200,201] and error is None:
error=request.text

Check warning on line 33 in superagi/helper/webhook_manager.py

View check run for this annotation

Codecov / codecov/patch

superagi/helper/webhook_manager.py#L33

Added line #L33 was not covered by tests
if error is not None:
status='Error'
webhook_event=WebhookEvents(agent_id=agent_id, run_id=agent_execution_id, event=f"{old_status} to {curr_status}", status=status, errors=error)
self.session.add(webhook_event)
self.session.commit()

Check warning on line 38 in superagi/helper/webhook_manager.py

View check run for this annotation

Codecov / codecov/patch

superagi/helper/webhook_manager.py#L35-L38

Added lines #L35 - L38 were not covered by tests

1 change: 1 addition & 0 deletions superagi/models/webhooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,4 @@ class Webhooks(DBBaseModel):
url = Column(String)
headers=Column(JSON)
is_deleted=Column(Boolean)
filters=Column(JSON)