2017-10-24 7 views
0

チャットの中でユーザーが会話をしたときに、他のチャットユーザーに電子メールが生成される機能を作成する必要があります。他のユーザーは電子メールを確認でき、同じ電子メールからチャットの会話に返信することができます。私は角の流星を使っています。この機能をどうすればできますか?電子メールからの呼び出しを処理し会話を追加するためのsendgridまたはmailgunにAPIがありますか?または、私はPOST/GETメソッドを作成して、メール内のボタンをクリックして応答したテキストを保存する必要がありますか?電子メールからチャットの会話に返信する方法

+0

は[ 'imap' NPMパッケージ](https://github.com/mscdex/node-imap)の上に独自のロジックを構築することは良いかもしれませんアイディア。 –

答えて

1

受信メールを受信したときに、サーバーにREST API呼び出しを行うようにsendgridに指示できます。

あなたは電子メールを送信し、返信するあなたは、これらの要求を処理するために、サーバーのコード内のエンドポイントを設定する@ chat-reply.myserver.com

のようなものにするために電子メールを設定します。あなたのコードは、着信アドレスから会話を検索する必要がありますし、チャットにレコードを保存することができます。ここで

は、いくつかのコードです...

import { Meteor } from 'meteor/meteor' 
formidable = require('formidable');  // Formidable does upload form/file parsing 
import { Profiles } from '../imports/api/collections'; 
import { inboundReply } from '../imports/api/inbound/methods.js'; 

const debug = require('debug')('myapp:inbound') 

// Needs to run on the server and client, why this is not in the routing.js file 
// which is only only runs on the client. 
// Inbound emails, for loop reply 
// 
// This is a RESTAPI end point which is called by sendgrid, 
// any email to [email protected] will come here. Our job 
// is to parse it , work out which loop it relates to, and save it as a message 
// in the database 
// 
Router.route('/inbound', function() { 

    // Need to use formidable because SendGrid inbound data is encoded as a multipart/form-data 
    const form = new formidable.IncomingForm(); 
    // Meteor bind eviron. to get callback 
    debug(this.request.body) 
    let r = this.response 
    form.parse(this.request, Meteor.bindEnvironment(function (error, fields, files) { 
     if (error) 
     console.error(error); 
     let errs = [] 

     // Gets the to field 
     const toField = _.find(fields, function(value, key) { if (key === 'to') { return value; }}); 

     // Gets the from field 
     const fromField = _.find(fields, function(value, key) { if (key === 'from') { return value; }}); 

     // Gets the html content, email 
     const content = _.find(fields, function(value, key) { if (key === 'text') { return value; }}); 

     let cleanContent; 
     if (content){ 
     // Logger.trace({content: content}); 
     // Regex removes html 
     // cleanContent = content.replace(/<br>/ig, "\n"); 
     // const regex = /(<([^>]+)>)/ig 
     // cleanContent = cleanContent.replace(regex, ""); 
     // Logger.trace({cleanContent: cleanContent}); 
     let lines = content.split(/\n/); 
     debug("Incoming body",lines); 
+0

お返事ありがとうございます。私はこれを実装します – Vaidya

+0

'const toField = fields.to;'ではなく '_.find(...)'を使うことで何ができますか? – Styx

+0

あなたは正しいです、それは最高のコードではありません:)他の人 – Mikkel

関連する問題