0

"How to send welcome greetings message using Bot, in Telegram"? Acctually i create new bot in telegram. and now i want , when new user start my bot, my bot send him Welcome greetings message? is it possible with "getupdates" method or i should use "webhooks" for it? pls guide me.

I have create one bot like @mak_tech_bot. and join it with my other telegram accout, but it not send any welcome message. i have also use /command.

I also tried one example in localhost

<?php
ini_set('error_reporting',E_ALL);
$botToken = "TOKEN";
$website = "https://api.telegram.org/bot".$botToken;

$update = file_get_contents('php://input');
$update = json_decode($update,TRUE);

$chatId = $update["message"]["chat"]["id"];
$message = $update["message"]["text"];

switch($message){
    case "/test":
        sendMessage($chatId,"test123");
        break;
    case "/hi":
        sendMessage($chatId,"Hello123");
        break;
    default:
        sendMessage($chatId,"default");
}

function sendMessage($chatId,$message){
    $url = $GLOBALS[website]."/sendMessage?chat_id=".$chatId."$text=".urlencode($message);
    file_get_contents($url);
}
?>
Sean Wei
  • 7,433
  • 1
  • 19
  • 39
mayank
  • 31
  • 1
  • 6

1 Answers1

0

When you click START button, you will send /start command to bot, just add case '/start': to your code to send greeting message.

Sean Wei
  • 7,433
  • 1
  • 19
  • 39
  • thankyou, but is it possible without webhook method, and i want to test it in my localhost, so is it possible? – mayank Aug 30 '17 at 05:48
  • It is possible without webhook. But then you _have_ to use [getUpdates](https://core.telegram.org/bots/api#getupdates). You need to have some mechanism to know if any interaction with your bot has been made. Using webhooks Telegram will deliever updates as soon as any are available. Using getUpdates you have to implement your own polling mechanism. – newsha Aug 30 '17 at 10:32