# About Inline Keyboard in Telegram and Widget

Inline keyboard allows displaying buttons directly under the message in Telegram and Widget. Unlike regular keyboard, inline buttons do not take up space in the user's permanent keyboard and allow more flexible interaction.

---

## Context and Problem

In many scenarios, you need to give users the ability to choose an action without entering text:
- Navigate to website
- Answer question with one click
- Navigate through menu
- Quick actions

Inline keyboard solves this task by allowing adding buttons directly to the message.

---

## Key Concepts

### Differences from Regular Keyboard

**Inline keyboard:**
- Displayed directly under the message
- Does not take up space in permanent keyboard
- Can contain links and special actions
- Works only for Telegram and Widget

**Regular keyboard:**
- Replaces user's standard keyboard
- Takes up entire keyboard space
- Limited to text responses
- Works for all channels

### Button Action Types

Inline keyboard supports different action types through `ActionType` parameter:
- `reply` — sending response text (default)
- `open-url` — opening link
- `none` — button without action

---

## Approach Options

### Inline Keyboard vs Regular Keyboard

**Inline keyboard:**
- ✅ Pros: Does not take up keyboard space, supports links, more flexible
- ❌ Cons: Works only for Telegram and Widget

**Regular keyboard:**
- ✅ Pros: Works for all channels, always visible
- ❌ Cons: Takes up entire keyboard space, limited to text responses

**Why we use inline keyboard:**
For Telegram and Widget, inline keyboard provides more capabilities and does not take up permanent keyboard space, making the interface more convenient.

---

## Adopted Solutions

### Limited Channel Support

Inline keyboard works only for Telegram and Widget due to API limitations of other channels. For Viber and Facebook Messenger, you need to use regular keyboard.

### Required Protocol for Links

Links in `ActionBody` must have `https://` or `http://` protocol. This is a Telegram API requirement for security.

### Link Confirmation Pop-up

When clicking a button with a link (`ActionType: "open-url"`), a pop-up opens asking whether to open the link and the site name. This ensures user security.

---

## Implications for Users and Implementation

### For Integrators

When using inline keyboard, it's important to:

1. **Check channel** — inline keyboard works only for Telegram and Widget
2. **Enable option** — must check "Inline keyboard (Telegram and Widget only)" checkbox
3. **Configure ActionType** — specify action type for each button
4. **Add protocol to links** — links must have `https://` or `http://` protocol

### Common Errors

**Error:** Inline keyboard does not display  
**Problem:** "Inline keyboard" checkbox is not checked  
**Solution:** Enable inline keyboard option in block settings

**Error:** Link does not work  
**Problem:** Link does not have protocol or incorrect `ActionType`  
**Solution:** Add `https://` protocol and specify `ActionType: "open-url"`

**Error:** Button does not send response  
**Problem:** `ActionBody` is not specified or incorrect `ActionType`  
**Solution:** Specify `ActionType: "reply"` and text in `ActionBody`

### Limitations

- Inline keyboard works only for Telegram and Widget
- Maximum button count per row: 8 (for Telegram)
- Maximum row count: depends on channel
- Links must have `https://` or `http://` protocol

---

## Usage Examples

### Button with Website Navigation

```json
{
  "ActionType": "open-url",
  "ActionBody": "https://example.com"
}
```

### Button with Response

```json
{
  "ActionType": "reply",
  "ActionBody": "Yes, I agree"
}
```

Or you can omit `ActionType`, then `reply` will be used by default.

---

## Related Documents

- **Reference:** [Telegram Bot API - Inline Keyboard](https://core.telegram.org/bots/api#inlinekeyboardmarkup) — official Telegram documentation about inline keyboards
- **Explanation:** [Telegram WebApp](/en/scenariodialog/explanation/telegram-webapp.md) — using WebApp through inline keyboard

