-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsimpleTeleBot.py
More file actions
48 lines (40 loc) · 1.72 KB
/
simpleTeleBot.py
File metadata and controls
48 lines (40 loc) · 1.72 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import telebot
token = 'your_bot_token'
bot = telebot.TeleBot(token)
#command /start
@bot.message_handler(commands=['start'])
def send_welcome(message):
bot.reply_to(message, "haloooo, ada yang bisa saya bantu?")
#command untuk trigger send contanct
@bot.message_handler(commands=['contact'])
def share(message):
keyboard = types.ReplyKeyboardMarkup(one_time_keyboard=False)
reg_button = types.KeyboardButton(text="bagikan kontak anda", request_contact=True)
keyboard.add(reg_button)
bot.send_message(message.from_user.id, "Bagikan kontak anda", reply_markup=keyboard)
#content_types untuk share contact
@bot.message_handler(content_types=['contact'])
def contact(message):
markup = types.ReplyKeyboardRemove(selective=False)
bot.send_message(message.from_user.id, "Nama: "+message.from_user.first_name+"\r\nTelepon: "+message.contact.phone_number, reply_markup=markup)
#command untuk trigger share location
@bot.message_handler(commands=['sendloc'])
def sendloc(message):
keyboard = types.ReplyKeyboardMarkup(one_time_keyboard=False)
reg_button = types.KeyboardButton(text="bagikan lokasi anda", request_location=True)
keyboard.add(reg_button)
bot.send_message(message.from_user.id, "Bagikan lokasi anda", reply_markup=keyboard)
#content_types untuk share location
@bot.message_handler(content_types=['location'])
def location(message):
userid = message.from_user.id
lat = message.location.latitude
lon = message.location.longitude
markup = types.ReplyKeyboardRemove(selective=False)
bot.send_location(userid, lat, lon)
@bot.message_handler(func=lambda message: True)
def echo_all(message):
chat = message.text
bot.reply_to(message, "Kamu mengirim chat: '"+str(chat)+"'")
if __name__ == '__main__':
bot.polling(none_stop=True)