Skip to content

Commit

Permalink
Add share_contact example by @hamidb80, refs #68
Browse files Browse the repository at this point in the history
  • Loading branch information
ba0f3 committed Jan 1, 2022
1 parent d4be7aa commit ecb8dc1
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions examples/share_contact.nim
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import telebot, asyncdispatch, logging, options, strutils

#[
this example has been shared by @ @hamidb80
https://github.com/ba0f3/telebot.nim/issues/68
]#

var L = newConsoleLogger(fmtStr = "$levelname, [$time] ")
addHandler(L)

func singleReply*(btn: KeyboardButton): ReplyKeyboardMarkup =
ReplyKeyboardMarkup(`type`: kReplyKeyboardMarkup, keyboard: @[@[btn]])

const API_KEY = slurp("secret.key").strip()

proc updateHandler(b: Telebot, u: Update): Future[bool] {.gcsafe, async.} =
if u.message.isSome:
var response = u.message.get

discard await b.sendMessage(
response.chat.id,
"check the virtual keyboard",
replyMarkup = singleReply(
KeyboardButton(text: "send your contact", requestContact: some true)
)
)
return true

let bot = newTeleBot(API_KEY)

while true:
try:
bot.onUpdate(updateHandler)
bot.poll(timeout=300)
except:
echo getCurrentExceptionMsg()
continue

0 comments on commit ecb8dc1

Please sign in to comment.