Core: Need help performing greeting for a new members

Created on 20 Aug 2017  路  19Comments  路  Source: php-telegram-bot/core

Required Information

  • Operating system: Uniz
  • PHP version: 7.1.6
  • PHP Telegram Bot version: latest
  • Using MySQL database: no
  • MySQL version:
  • Update Method: Webhook
  • Self-signed certificate: yes
  • RAW update (if available):

Expected behaviour

the bot will give the right answer or greeting automatically when new user join the chatroom

Actual behaviour

N/A

Steps to reproduce

Need to learn how

Extra details

Is there a guide or sample for this using message -> new_chat_member command. This way hook.php will notice when a new chat members join the room

All 19 comments

Take a look at this: https://github.com/php-telegram-bot/example-bot/blob/master/Commands/NewchatmembersCommand.php, it does exactly what you want I guess.

@jacklul yes I examine the code, however I'm not sure how to activated this command. What need to be written on hook.php so it will run it when new user join the chatroom. Any help will be greatly appriciated

@jacklul did the hook.php and it work for most command. However automatically do a greeting for a new chat user is not being called.

Did you tried copying that NewchatmembersCommand.php from example-bot repository into your project's commands dir?

@ranrinc You have downloaded the example NewchatmembersCommand from the example-bot repository, right?

edit: GitHub just refreshed and I saw that @jacklul beat me to it :+1:

@noplanman off course.. its already in command folder.

Just to make sure: is your 'latest' library version at least 0.45.0 ?

@jacklul its the latest library.. just wondering if I need to embeded specific code line on hook.php? Something that automatically trigger when new user join the chat?

It should be triggered automatically if custom command path is pointing to folder where mentioned command class is.

@ranrinc Did you get this to work now?

@noplanman unfortunately no...:(

Could you post your NewchatmembersCommand.php file?

If you have it in a folder that gets added as a custom commands path, then there must be a problem in that file 馃

```` /**

  • This file is part of the TelegramBot package.
    *
  • (c) Avtandil Kikabidze aka LONGMAN akalongman@gmail.com
    *
  • For the full copyright and license information, please view the LICENSE
  • file that was distributed with this source code.
    */

namespace Longman\TelegramBot\Commands\SystemCommands;

use Longman\TelegramBot\Commands\SystemCommand;
use Longman\TelegramBot\Request;

/**

  • New chat member command
    /
    class NewchatmembersCommand extends SystemCommand
    {
    /
    *

    • @var string

      */

      protected $name = 'newchatmembers';

/**
 * @var string
 */
protected $description = 'New Chat Members';

/**
 * @var string
 */
protected $version = '1.2.0';

/**
 * Command execute method
 *
 * @return \Longman\TelegramBot\Entities\ServerResponse
 * @throws \Longman\TelegramBot\Exception\TelegramException
 */
public function execute()
{
    $message = $this->getMessage();

    $chat_id = $message->getChat()->getId();
    $members = $message->getNewChatMembers();

    $text = 'Hi there!';

    if (!$message->botAddedInChat()) {
        $member_names = [];
        foreach ($members as $member) {
            $member_names[] = $member->tryMention();
        }
        $text = 'Hi ' . implode(', ', $member_names) . '!';
    }

    $data = [
        'chat_id' => $chat_id,
        'text'    => $text,
    ];

    return Request::sendMessage($data);
}

}
````

@noplanman I did not made any changes

Ok, that's strange then.

Could you get in touch on Telegram please? My username is noplanman

Have you found the problem or is it still not working?

This issue still exists now,It's still not working.
I am trying figure it out.

This issue has been resolved in NewChatMembers Command not working #1108 .

Was this page helpful?
0 / 5 - 0 ratings

Related issues

TheSleepySlee picture TheSleepySlee  路  3Comments

abbe-cipher picture abbe-cipher  路  4Comments

mohsenshahab picture mohsenshahab  路  4Comments

NabiKAZ picture NabiKAZ  路  4Comments

esomkin picture esomkin  路  3Comments