PHP:在bot电报和twitter之间连接

时间:2015-07-13 07:17:06

标签: php twitter telegram-bot

我需要将我的机器人电报与我在twitter上的帐户联系起来,所以,当我在Twitter上发布新推文时,我们需要发布新的电报。

怎么做呢。

2 个答案:

答案 0 :(得分:1)

只需将您的机器人令牌添加到电报中的@manybot即可。然后您的机器人将有从RSS和Twitter自动发布的选项。无需编码。

答案 1 :(得分:0)

我建议你为你的机器人使用cron。让它每分钟左右轮询你的推特RSS feed / API,如果它发现了新的推文......它可以将它转发给你的聊天。您可能必须使用Memcache或Redis之类的东西将import java.util.*; import java.io.*; public class App { private int exit = 0; private int createANote; private int displayTheNotes; private int inputFromUser; public boolean haveFileBeenWritten = true; File file = new File("Notes.txt"); Scanner input = new Scanner(System.in); ArrayList<Notes> arrayOfNotes = new ArrayList<Notes>(); public void makeNoteObject() { arrayOfNotes.add(new Notes()); } public void displayAllTheNote(ArrayList<Notes> n) { for(Notes singleObjectOfNote : n) { System.out.println(singleObjectOfNote); } } public void programUI(){ while(exit != 1) { System.out.println("1. Create A Note"); System.out.println("2. Display The Notes"); System.out.println("3. Exit"); System.out.println("4. Export to text file"); System.out.println("Enter Your Operation"); inputFromUser = input.nextInt(); if(inputFromUser == 1) { makeNoteObject(); } else if(inputFromUser == 2) { displayAllTheNote(arrayOfNotes); } else if(inputFromUser == 3) { System.out.println("Exited"); exit = 1; } else if(inputFromUser == 4) { makeATxtFileFromNotes(arrayOfNotes); System.out.println("Textfile created filename: " + file.toString()); } else { System.out.println("You Select A Invalid Command"); } } } public void makeATxtFileFromNotes(ArrayList<Notes> x) { try (BufferedWriter bw = new BufferedWriter(new FileWriter(file,haveFileBeenWritten))) { //Problem here! for(Notes singleObjectOfNotes : x) { bw.write(singleObjectOfNotes.toString()); bw.newLine(); } }catch(IOException e) { System.out.println("Cant Write File: " + file.toString()); haveFileBeenWritten = false; } } public App() { programUI(); } public static void main(String[]args) { App objectOfApp = new App(); } } chat_id存储在缓存中。