Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
13 changes: 13 additions & 0 deletions docs/content/docs/tools/jira.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,19 @@ import { BlockInfoCard } from "@/components/ui/block-info-card"
</svg>`}
/>

[Jira](https://www.atlassian.com/jira) is a leading project management and issue tracking platform that helps teams plan, track, and manage agile software development projects effectively. As part of the Atlassian suite, Jira has become the industry standard for software development teams and project management professionals worldwide.

Jira provides a comprehensive set of tools for managing complex projects through its flexible and customizable workflow system. With its robust API and integration capabilities, Jira enables teams to streamline their development processes and maintain clear visibility of project progress.

Key features of Jira include:

- Agile Project Management: Support for Scrum and Kanban methodologies with customizable boards and workflows
- Issue Tracking: Sophisticated tracking system for bugs, stories, epics, and tasks with detailed reporting
- Workflow Automation: Powerful automation rules to streamline repetitive tasks and processes
- Advanced Search: JQL (Jira Query Language) for complex issue filtering and reporting

In Sim Studio, the Jira integration allows your agents to seamlessly interact with your project management workflow. This creates opportunities for automated issue creation, updates, and tracking as part of your AI workflows. The integration enables agents to create, retrieve, and update Jira issues programmatically, facilitating automated project management tasks and ensuring that important information is properly tracked and documented. By connecting Sim Studio with Jira, you can build intelligent agents that maintain project visibility while automating routine project management tasks, enhancing team productivity and ensuring consistent project tracking.

## Usage Instructions

Connect to Jira workspaces to read, write, and update issues. Access content, metadata, and integrate Jira documentation into your workflows.
Expand Down
100 changes: 100 additions & 0 deletions docs/content/docs/tools/telegram.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
---
title: Telegram
description: Send a message through Telegram
---

import { BlockInfoCard } from "@/components/ui/block-info-card"

<BlockInfoCard
type="telegram"
color="#E0E0E0"
icon={true}
iconSvg={`<svg className="block-icon"



viewBox="-5 0 41 33"
fill="none"
xmlns="http://www.w3.org/2000/svg"
>
<circle cx="16" cy="16" r="14" fill="url(#paint0_linear_87_7225)"/>
<path
d="M22.9866 10.2088C23.1112 9.40332 22.3454 8.76755 21.6292 9.082L7.36482 15.3448C6.85123 15.5703 6.8888 16.3483 7.42147 16.5179L10.3631 17.4547C10.9246 17.6335 11.5325 17.541 12.0228 17.2023L18.655 12.6203C18.855 12.4821 19.073 12.7665 18.9021 12.9426L14.1281 17.8646C13.665 18.3421 13.7569 19.1512 14.314 19.5005L19.659 22.8523C20.2585 23.2282 21.0297 22.8506 21.1418 22.1261L22.9866 10.2088Z"
fill="white"/>
<defs>
<linearGradient id="paint0_linear_87_7225" x1="16" y1="2" x2="16" y2="30"
gradientUnits="userSpaceOnUse">
<stop stopColor="#37BBFE"/>
<stop offset="1" stopColor="#007DBB"/>
</linearGradient>
</defs>
</svg>`}
/>

[Telegram](https://telegram.org) is a secure, cloud-based messaging platform that enables fast and reliable communication across devices and platforms. With over 700 million monthly active users, Telegram has established itself as one of the world's leading messaging services, known for its security, speed, and powerful API capabilities.

<iframe width="100%" height="400" src="https://www.youtube.com/embed/nhq2Q8fndFg?start=62" title="Use Telegram with Sim Studio" frameBorder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowFullScreen ></iframe>

Telegram's Bot API provides a robust framework for creating automated messaging solutions and integrating communication features into applications. With support for rich media, inline keyboards, and custom commands, Telegram bots can facilitate sophisticated interaction patterns and automated workflows.

Key features of Telegram include:

- Secure Communication: End-to-end encryption and secure cloud storage for messages and media
- Bot Platform: Powerful bot API for creating automated messaging solutions and interactive experiences
- Rich Media Support: Send and receive messages with text formatting, images, files, and interactive elements
- Global Reach: Connect with users worldwide with support for multiple languages and platforms

In Sim Studio, the Telegram integration enables your agents to leverage these powerful messaging capabilities as part of their workflows. This creates opportunities for automated notifications, alerts, and interactive conversations through Telegram's secure messaging platform. The integration allows agents to send messages programmatically to individuals or channels, enabling timely communication and updates. By connecting Sim Studio with Telegram, you can build intelligent agents that engage users through a secure and widely-adopted messaging platform, perfect for delivering notifications, updates, and interactive communications.
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing webhook functionality description despite PR description mentioning webhook implementation


## Usage Instructions

Send messages to any Telegram channel using your Bot API key. Integrate automated notifications and alerts into your workflow to keep your team informed.



## Tools

### `telegram_message`

Send messages to Telegram channels or users through the Telegram Bot API. Enables direct communication and notifications with message tracking and chat confirmation.

#### Input

| Parameter | Type | Required | Description |
| --------- | ---- | -------- | ----------- |
| `botToken` | string | Yes | Your Telegram Bot API Token |
| `chatId` | string | Yes | Target Telegram chat ID |
| `text` | string | Yes | Message text to send |

#### Output

| Parameter | Type |
| --------- | ---- |
| `ok` | string |
| `date` | string |



## Block Configuration

### Input

| Parameter | Type | Required | Description |
| --------- | ---- | -------- | ----------- |
| `botToken` | string | Yes | Bot Token - Enter your Telegram Bot Token |



### Outputs

| Output | Type | Description |
| ------ | ---- | ----------- |
| `response` | object | Output from response |
| ↳ `ok` | boolean | ok of the response |
| ↳ `result` | json | result of the response |


## Notes

- Category: `tools`
- Type: `telegram`
63 changes: 60 additions & 3 deletions sim/app/api/webhooks/[id]/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -160,13 +160,70 @@ export async function DELETE(
return NextResponse.json({ error: 'Unauthorized' }, { status: 403 })
}

// Delete the webhook
const foundWebhook = webhooks[0].webhook

// If it's a Telegram webhook, delete it from Telegram first
if (foundWebhook.provider === 'telegram') {
try {
const { botToken } = foundWebhook.providerConfig as { botToken: string }

if (!botToken) {
logger.warn(`[${requestId}] Missing botToken for Telegram webhook deletion.`, {
webhookId: id,
})
return NextResponse.json(
{ error: 'Missing botToken for Telegram webhook deletion' },
{ status: 400 }
)
}

const telegramApiUrl = `https://api.telegram.org/bot${botToken}/deleteWebhook`
const telegramResponse = await fetch(telegramApiUrl, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
}
})

const responseBody = await telegramResponse.json()
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing error handling for json parsing which could throw if response is not valid JSON

if (!telegramResponse.ok || !responseBody.ok) {
const errorMessage = responseBody.description || `Failed to delete Telegram webhook. Status: ${telegramResponse.status}`
logger.error(`[${requestId}] ${errorMessage}`, {
response: responseBody
})
return NextResponse.json(
{ error: 'Failed to delete webhook from Telegram', details: errorMessage },
{ status: 500 }
)
}

logger.info(`[${requestId}] Successfully deleted Telegram webhook for webhook ${id}`)
} catch (error: any) {
logger.error(`[${requestId}] Error deleting Telegram webhook`, {
webhookId: id,
error: error.message,
stack: error.stack,
})
return NextResponse.json(
{
error: 'Failed to delete webhook from Telegram',
details: error.message
},
{ status: 500 }
)
}
}

// Delete the webhook from the database
await db.delete(webhook).where(eq(webhook.id, id))

logger.info(`[${requestId}] Successfully deleted webhook: ${id}`)
return NextResponse.json({ success: true }, { status: 200 })
} catch (error) {
logger.error(`[${requestId}] Error deleting webhook`, error)
} catch (error: any) {
logger.error(`[${requestId}] Error deleting webhook`, {
error: error.message,
stack: error.stack
})
return NextResponse.json({ error: 'Internal server error' }, { status: 500 })
}
}
89 changes: 89 additions & 0 deletions sim/app/api/webhooks/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,26 @@ export async function POST(request: NextRequest) {
}
// --- End Airtable specific logic ---

// --- Attempt to create webhook in Telegram if provider is 'telegram' ---
if (savedWebhook && provider === 'telegram') {
logger.info(
`[${requestId}] Telegram provider detected. Attempting to create webhook in Telegram.`
)
try {
await createTelegramWebhookSubscription(request, userId, savedWebhook, requestId)
} catch (err) {
logger.error(`[${requestId}] Error creating Telegram webhook`, err)
return NextResponse.json(
{
error: 'Failed to create webhook in Telegram',
details: err instanceof Error ? err.message : 'Unknown error',
},
{ status: 500 }
)
}
}
// --- End Telegram specific logic ---

const status = existingWebhooks.length > 0 ? 200 : 201
return NextResponse.json({ webhook: savedWebhook }, { status })
} catch (error: any) {
Expand Down Expand Up @@ -289,3 +309,72 @@ async function createAirtableWebhookSubscription(
)
}
}

// Helper function to create the webhook subscription in Telegram
async function createTelegramWebhookSubscription(
request: NextRequest,
userId: string,
webhookData: any,
requestId: string
) {
try {
const { path, providerConfig } = webhookData
const { botToken, triggerPhrase } = providerConfig || {}

if (!botToken || !triggerPhrase) {
logger.warn(`[${requestId}] Missing botToken or triggerPhrase for Telegram webhook creation.`, {
webhookId: webhookData.id,
})
return // Cannot proceed without botToken and triggerPhrase
}

const requestOrigin = new URL(request.url).origin
// Ensure origin does not point to localhost for external API calls
const effectiveOrigin = requestOrigin.includes('localhost')
? process.env.NEXT_PUBLIC_APP_URL || requestOrigin // Use env var if available, fallback to original
: requestOrigin

const notificationUrl = `${effectiveOrigin}/api/webhooks/trigger/${path}`
if (effectiveOrigin !== requestOrigin) {
logger.debug(
`[${requestId}] Remapped localhost origin to ${effectiveOrigin} for notificationUrl`
)
}

const telegramApiUrl = `https://api.telegram.org/bot${botToken}/setWebhook`

const requestBody: any = {
url: notificationUrl,
allowed_updates: ['message'],
}

const telegramResponse = await fetch(telegramApiUrl, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify(requestBody),
})

const responseBody = await telegramResponse.json()
if (!telegramResponse.ok || !responseBody.ok) {
const errorMessage = responseBody.description || `Failed to create Telegram webhook. Status: ${telegramResponse.status}`
logger.error(`[${requestId}] ${errorMessage}`, {
response: responseBody
})
throw new Error(errorMessage)
}

logger.info(
`[${requestId}] Successfully created Telegram webhook for webhook ${webhookData.id}.`
)
} catch (error: any) {
logger.error(
`[${requestId}] Exception during Telegram webhook creation for webhook ${webhookData.id}.`,
{
message: error.message,
stack: error.stack,
}
)
}
}
Loading