Skip to content

Commit

Permalink
Merge pull request #41 from nutgram/sync-nutgram
Browse files Browse the repository at this point in the history
Sync to Nutgram latest changes
  • Loading branch information
Lukasss93 authored Dec 6, 2023
2 parents f1734cf + 19c575a commit d7aec3f
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 31 deletions.
35 changes: 35 additions & 0 deletions docs/usage/conversations.md
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,8 @@ $bot->onCommand('start', function (Nutgram $bot) {
$bot->run();
```

### Starting a conversation from server-side

You can also start a conversation from server-side, without any user interaction:

```php
Expand All @@ -175,6 +177,39 @@ Starting a conversation from server-side, will not give you a Telegram update, s
`$bot->chatId()` and `$bot->userId()` methods, you need to pass them manually!
:::

### Passing parameters to a conversation

You can also pass parameters to a conversation.

Consider the following example:

```php
class StartConversation extends Conversation
{
public function start(Nutgram $bot, string $name)
{
$bot->sendMessage("Hello $name");
$this->end();
}
}
```

#### Via handler

```php
$bot->onCommand('start {name}', StartConversation::class);
```

#### Via the `begin` method

```php
$bot->onCommand('start', function (Nutgram $bot) {
StartConversation::begin($bot, data: [
'name' => 'static name',
]);
});
```

## Funnel Escaping

By default, sends a message that match with a typed **specific** handler, the current conversation will be discarded, in
Expand Down
64 changes: 37 additions & 27 deletions docs/usage/handlers.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@ Here a full list of all the handler that listens to specific type of updates:

### Update Handlers

<div class="margin-bottom--md">
<img style={{verticalAlign: 'middle'}} src="https://img.shields.io/badge/-GENERIC-brightgreen"/>&nbsp;
<code>onUpdate($callable)</code><br/>
Handles any incoming update.
</div>
<div class="margin-bottom--md">
<img style={{verticalAlign: 'middle'}} src="https://img.shields.io/badge/-GENERIC-brightgreen"/>&nbsp;
<code>onMessage($callable)</code><br/>
Expand Down Expand Up @@ -134,62 +139,62 @@ Here a full list of all the handler that listens to specific type of updates:

<div class="margin-bottom--md">
<img style={{verticalAlign: 'middle'}} src="https://img.shields.io/badge/-SPECIFIC-blue"/>&nbsp;
<code>onText(string $pattern, $callable)</code><br/>
<code>onText(string $pattern, $callable, UpdateType $target = UpdateType::MESSAGE)</code><br/>
Handles text messages that match the given pattern (regex or parameters).
</div>
<div class="margin-bottom--md">
<img style={{verticalAlign: 'middle'}} src="https://img.shields.io/badge/-SPECIFIC-blue"/>&nbsp;
<code>onCommand(string $command, $callable)</code><br/>
<code>onCommand(string $command, $callable, UpdateType $target = UpdateType::MESSAGE)</code><br/>
Handles text messages that begin with `/`.<br/>Automatically parses commands like `cmd@botname`.
</div>
<div class="margin-bottom--md">
<img style={{verticalAlign: 'middle'}} src="https://img.shields.io/badge/-GENERIC-brightgreen"/>&nbsp;
<code>onAnimation($callable)</code><br/>
<code>onAnimation($callable, UpdateType $target = UpdateType::MESSAGE)</code><br/>
Handles animation messages
</div>
<div class="margin-bottom--md">
<img style={{verticalAlign: 'middle'}} src="https://img.shields.io/badge/-GENERIC-brightgreen"/>&nbsp;
<code>onAudio($callable)</code><br/>
<code>onAudio($callable, UpdateType $target = UpdateType::MESSAGE)</code><br/>
Handles audio messages.
</div>
<div class="margin-bottom--md">
<img style={{verticalAlign: 'middle'}} src="https://img.shields.io/badge/-GENERIC-brightgreen"/>&nbsp;
<code>onDocument($callable)</code><br/>
<code>onDocument($callable, UpdateType $target = UpdateType::MESSAGE)</code><br/>
Handles document messages.
</div>
<div class="margin-bottom--md">
<img style={{verticalAlign: 'middle'}} src="https://img.shields.io/badge/-GENERIC-brightgreen"/>&nbsp;
<code>onPhoto($callable)</code><br/>
<code>onPhoto($callable, UpdateType $target = UpdateType::MESSAGE)</code><br/>
Handles photo messages.
</div>
<div class="margin-bottom--md">
<img style={{verticalAlign: 'middle'}} src="https://img.shields.io/badge/-GENERIC-brightgreen"/>&nbsp;
<code>onSticker($callable)</code><br/>
<code>onSticker($callable, UpdateType $target = UpdateType::MESSAGE)</code><br/>
Handles sticker messages.
</div>
<div class="margin-bottom--md">
<img style={{verticalAlign: 'middle'}} src="https://img.shields.io/badge/-GENERIC-brightgreen"/>&nbsp;
<code>onVideo($callable)</code><br/>
<code>onVideo($callable, UpdateType $target = UpdateType::MESSAGE)</code><br/>
Handles video messages.
</div>
<div class="margin-bottom--md">
<img style={{verticalAlign: 'middle'}} src="https://img.shields.io/badge/-GENERIC-brightgreen"/>&nbsp;
<code>onVideoNote($callable)</code><br/>
<code>onVideoNote($callable, UpdateType $target = UpdateType::MESSAGE)</code><br/>
Handles video_note messages.
</div>
<div class="margin-bottom--md">
<img style={{verticalAlign: 'middle'}} src="https://img.shields.io/badge/-GENERIC-brightgreen"/>&nbsp;
<code>onVoice($callable)</code><br/>
<code>onVoice($callable, UpdateType $target = UpdateType::MESSAGE)</code><br/>
Handles voice messages.
</div>
<div class="margin-bottom--md">
<img style={{verticalAlign: 'middle'}} src="https://img.shields.io/badge/-GENERIC-brightgreen"/>&nbsp;
<code>onContact($callable)</code><br/>
<code>onContact($callable, UpdateType $target = UpdateType::MESSAGE)</code><br/>
Handles contact messages.
</div>
<div class="margin-bottom--md">
<img style={{verticalAlign: 'middle'}} src="https://img.shields.io/badge/-GENERIC-brightgreen"/>&nbsp;
<code>onDice($callable)</code><br/>
<code>onDice($callable, UpdateType $target = UpdateType::MESSAGE)</code><br/>
Handles dice messages.
</div>
<div class="margin-bottom--md">
Expand All @@ -199,42 +204,47 @@ Here a full list of all the handler that listens to specific type of updates:
</div>
<div class="margin-bottom--md">
<img style={{verticalAlign: 'middle'}} src="https://img.shields.io/badge/-GENERIC-brightgreen"/>&nbsp;
<code>onMessagePoll($callable)</code><br/>
<code>onMessagePoll($callable, UpdateType $target = UpdateType::MESSAGE)</code><br/>
Handles poll messages.
</div>
<div class="margin-bottom--md">
<img style={{verticalAlign: 'middle'}} src="https://img.shields.io/badge/-GENERIC-brightgreen"/>&nbsp;
<code>onVenue($callable)</code><br/>
<code>onVenue($callable, UpdateType $target = UpdateType::MESSAGE)</code><br/>
Handles venue messages.
</div>
<div class="margin-bottom--md">
<img style={{verticalAlign: 'middle'}} src="https://img.shields.io/badge/-GENERIC-brightgreen"/>&nbsp;
<code>onLocation($callable)</code><br/>
<code>onLocation($callable, UpdateType $target = UpdateType::MESSAGE)</code><br/>
Handles location messages.
</div>
<div class="margin-bottom--md">
<img style={{verticalAlign: 'middle'}} src="https://img.shields.io/badge/-GENERIC-brightgreen"/>&nbsp;
<code>onNewChatMembers($callable)</code><br/>
<code>onStory($callable, UpdateType $target = UpdateType::MESSAGE)</code><br/>
Handles story messages.
</div>
<div class="margin-bottom--md">
<img style={{verticalAlign: 'middle'}} src="https://img.shields.io/badge/-GENERIC-brightgreen"/>&nbsp;
<code>onNewChatMembers($callable, UpdateType $target = UpdateType::MESSAGE)</code><br/>
Handles new_chat_members messages.
</div>
<div class="margin-bottom--md">
<img style={{verticalAlign: 'middle'}} src="https://img.shields.io/badge/-GENERIC-brightgreen"/>&nbsp;
<code>onLeftChatMember($callable)</code><br/>
<code>onLeftChatMember($callable, UpdateType $target = UpdateType::MESSAGE)</code><br/>
Handles left_chat_member messages.
</div>
<div class="margin-bottom--md">
<img style={{verticalAlign: 'middle'}} src="https://img.shields.io/badge/-GENERIC-brightgreen"/>&nbsp;
<code>onNewChatTitle($callable)</code><br/>
<code>onNewChatTitle($callable, UpdateType $target = UpdateType::MESSAGE)</code><br/>
Handles new_chat_title messages.
</div>
<div class="margin-bottom--md">
<img style={{verticalAlign: 'middle'}} src="https://img.shields.io/badge/-GENERIC-brightgreen"/>&nbsp;
<code>onNewChatPhoto($callable)</code><br/>
<code>onNewChatPhoto($callable, UpdateType $target = UpdateType::MESSAGE)</code><br/>
Handles new_chat_photo messages.
</div>
<div class="margin-bottom--md">
<img style={{verticalAlign: 'middle'}} src="https://img.shields.io/badge/-GENERIC-brightgreen"/>&nbsp;
<code>onDeleteChatPhoto($callable)</code><br/>
<code>onDeleteChatPhoto($callable, UpdateType $target = UpdateType::MESSAGE)</code><br/>
Handles delete_chat_photo messages.
</div>
<div class="margin-bottom--md">
Expand All @@ -249,12 +259,12 @@ Here a full list of all the handler that listens to specific type of updates:
</div>
<div class="margin-bottom--md">
<img style={{verticalAlign: 'middle'}} src="https://img.shields.io/badge/-GENERIC-brightgreen"/>&nbsp;
<code>onChannelChatCreated($callable)</code><br/>
<code>onChannelChatCreated($callable, UpdateType $target = UpdateType::MESSAGE)</code><br/>
Handles channel_chat_created messages.
</div>
<div class="margin-bottom--md">
<img style={{verticalAlign: 'middle'}} src="https://img.shields.io/badge/-GENERIC-brightgreen"/>&nbsp;
<code>onMessageAutoDeleteTimerChanged($callable)</code><br/>
<code>onMessageAutoDeleteTimerChanged($callable, UpdateType $target = UpdateType::MESSAGE)</code><br/>
Handles message_auto_delete_timer_changed messages.
</div>
<div class="margin-bottom--md">
Expand All @@ -269,7 +279,7 @@ Here a full list of all the handler that listens to specific type of updates:
</div>
<div class="margin-bottom--md">
<img style={{verticalAlign: 'middle'}} src="https://img.shields.io/badge/-GENERIC-brightgreen"/>&nbsp;
<code>onPinnedMessage($callable)</code><br/>
<code>onPinnedMessage($callable, UpdateType $target = UpdateType::MESSAGE)</code><br/>
Handles pinned_message messages.
</div>
<div class="margin-bottom--md">
Expand Down Expand Up @@ -320,22 +330,22 @@ Here a full list of all the handler that listens to specific type of updates:
</div>
<div class="margin-bottom--md">
<img style={{verticalAlign: 'middle'}} src="https://img.shields.io/badge/-GENERIC-brightgreen"/>&nbsp;
<code>onVideoChatScheduled($callable)</code><br/>
<code>onVideoChatScheduled($callable, UpdateType $target = UpdateType::MESSAGE)</code><br/>
Handles video_chat_scheduled messages.
</div>
<div class="margin-bottom--md">
<img style={{verticalAlign: 'middle'}} src="https://img.shields.io/badge/-GENERIC-brightgreen"/>&nbsp;
<code>onVideoChatStarted($callable)</code><br/>
<code>onVideoChatStarted($callable, UpdateType $target = UpdateType::MESSAGE)</code><br/>
Handles video_chat_started messages.
</div>
<div class="margin-bottom--md">
<img style={{verticalAlign: 'middle'}} src="https://img.shields.io/badge/-GENERIC-brightgreen"/>&nbsp;
<code>onVideoChatEnded($callable)</code><br/>
<code>onVideoChatEnded($callable, UpdateType $target = UpdateType::MESSAGE)</code><br/>
Handles video_chat_ended messages.
</div>
<div class="margin-bottom--md">
<img style={{verticalAlign: 'middle'}} src="https://img.shields.io/badge/-GENERIC-brightgreen"/>&nbsp;
<code>onVideoChatParticipantsInvited($callable)</code><br/>
<code>onVideoChatParticipantsInvited($callable, UpdateType $target = UpdateType::MESSAGE)</code><br/>
Handles video_chat_participants_invited messages.
</div>
<div class="margin-bottom--md">
Expand Down
4 changes: 0 additions & 4 deletions docs/usage/web_validation.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
---
sidebar_label: Web Validation 🆕
---

# Web Validation

Nutgram provides a simple way to validate the data received from a Login Widget or a Mini App.
Expand Down

0 comments on commit d7aec3f

Please sign in to comment.