当前位置: 首页>>代码示例>>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;未经允许,请勿转载。