當前位置: 首頁>>代碼示例>>Python>>正文


Python TelegramBot.set_webhook方法代碼示例

本文整理匯總了Python中twx.botapi.TelegramBot.set_webhook方法的典型用法代碼示例。如果您正苦於以下問題:Python TelegramBot.set_webhook方法的具體用法?Python TelegramBot.set_webhook怎麽用?Python TelegramBot.set_webhook使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在twx.botapi.TelegramBot的用法示例。


在下文中一共展示了TelegramBot.set_webhook方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: start

# 需要導入模塊: from twx.botapi import TelegramBot [as 別名]
# 或者: from twx.botapi.TelegramBot import set_webhook [as 別名]
def start():
 bot = TelegramBot(token)
 bot.update_bot_info().wait()
 print(bot.username)
 #foto belle -33909375 
 #user_id = int(23263342)

 #result = bot.send_message(user_id, 'Salve ragazzi').wait()
 #XXX WebHook automatico non funzionante
 result = bot.set_webhook(token)
 print('*****Il risultato:' % (result))
 return "ok"
開發者ID:kmos,項目名稱:cosbytbot,代碼行數:14,代碼來源:flaskapp.py

示例2: messageFlush

# 需要導入模塊: from twx.botapi import TelegramBot [as 別名]
# 或者: from twx.botapi.TelegramBot import set_webhook [as 別名]
#	chat_id = update.message.chat.id;
	bot.send_message(chat_id, botSpeak).wait()

def messageFlush(bot):
	for i in range(1,300):
		time.sleep(0.04)
		bot.get_updates(i, limit=1)

print "Hello World!"

"""
Setup the bot
"""

bot = TelegramBot('172048491:AAG253i7GAR-AxQTX7bZlhlJmAPQu6n_3b0')
bot.set_webhook() # remove webhook
bot.update_bot_info().wait()
print(bot.username)

botUser = bot.get_me().wait()
print(botUser)

#updates = bot.get_updates(159).wait()
#for update in updates:
#	update=update

#print("update:           ", update)

#message_id = update.message.message_id;
#first_name = update.message.sender.first_name;
開發者ID:megaadam,項目名稱:zak,代碼行數:32,代碼來源:zak2.py

示例3: messageFlush

# 需要導入模塊: from twx.botapi import TelegramBot [as 別名]
# 或者: from twx.botapi.TelegramBot import set_webhook [as 別名]
def messageFlush(bot):
	for i in range(1,300):
		time.sleep(0.04)
		bot.get_updates(i, limit=1)

print "Hello World!"

"""
Setup the bot
"""
f = open( "./res/tgram_token", "r")
token = f.readline()
f.close()
bot = TelegramBot(token)

bot.set_webhook() # remove all webhooks
bot.update_bot_info().wait()
print(bot.username)

botUser = bot.get_me().wait()
print(botUser)

updates = bot.get_updates().wait()
while(updates == []):
	time.sleep(1.5)
	updates = bot.get_updates().wait()

for update in updates:
	update=update

update_id = update.update_id + 1;
開發者ID:megaadam,項目名稱:zak,代碼行數:33,代碼來源:zak.py

示例4: TGBot

# 需要導入模塊: from twx.botapi import TelegramBot [as 別名]
# 或者: from twx.botapi.TelegramBot import set_webhook [as 別名]

#.........這裏部分代碼省略.........
        if message.new_chat_participant is not None and message.new_chat_participant != self.me:
            try:
                models.User.create(
                    id=message.new_chat_participant.id,
                    first_name=message.new_chat_participant.first_name,
                    last_name=message.new_chat_participant.last_name,
                )
            except peewee.IntegrityError:
                pass  # ignore, already exists

        if message.contact is not None:
            try:
                models.User.create(
                    id=message.contact.user_id,
                    first_name=message.contact.first_name,
                    last_name=message.contact.last_name,
                )
            except peewee.IntegrityError:
                pass  # ignore, already exists

        if message.text is not None and message.text.startswith("/"):
            spl = message.text.find(" ")

            if spl < 0:
                cmd = message.text[1:]
                text = ""
            else:
                cmd = message.text[1:spl]
                text = message.text[spl + 1 :]

            spl = cmd.find("@")
            if spl > -1:
                cmd = cmd[:spl]

            self.process(message, cmd, text)
        else:
            was_expected = False
            for p in self._plugins:
                was_expected = p.is_expected(self, message)
                if was_expected:
                    break

            if self._no_cmd is not None and not was_expected:
                self._no_cmd.chat(self, message, message.text)

    def setup_db(self):
        models.create_tables(self.db)

    def run(self, polling_time=2):
        from time import sleep

        # make sure all webhooks are disabled
        self.tg.set_webhook().wait()

        while True:
            ups = self.tg.get_updates(offset=self._last_id).wait()
            if isinstance(ups, Error):
                print "Error: ", ups
            else:
                for up in ups:
                    self.process_update(up)
                    self._last_id = up.update_id + 1

            sleep(polling_time)

    def run_web(self, hook_url, **kwargs):
        from .webserver import run_server

        url = hook_url
        if url[-1] != "/":
            url += "/"
        self.tg.set_webhook(url + "update/" + self._token)
        run_server(self, **kwargs)

    def list_commands(self):
        return self.cmds.values() + self.pcmds.values()

    def print_commands(self, out=sys.stdout):
        """
        utility method to print commands
        and descriptions for @BotFather
        """
        cmds = self.list_commands()
        for ck in cmds:
            if ck.printable:
                out.write("%s\n" % ck)

    def process(self, message, cmd, text):
        if cmd in self.cmds:
            self.cmds[cmd].method(self, message, text)
        elif cmd in self.pcmds:
            self.pcmds[cmd].method(self, message, text)
        else:
            for pcmd in self.pcmds:
                if cmd.startswith(pcmd):
                    ntext = cmd[len(pcmd) :]
                    if text:
                        ntext += " " + text
                    self.pcmds[pcmd].method(self, message, ntext)
                    break
開發者ID:pmpfl,項目名稱:tgbotplug,代碼行數:104,代碼來源:tgbot.py


注:本文中的twx.botapi.TelegramBot.set_webhook方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。